Skip to content

TypeError Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. #14534

@Shu-Ji

Description

@Shu-Ji

Version

5.0.2

Reproduction link

https://codesandbox.io/s/echart-areastyle-null-error-r37t0?file=/src/index.js

Steps to reproduce

面积图中有两条线:
由于需求要求同环比,就会存在:本周有数据,但是上周可能没数据的情况
即 series 中有一个线有数据,有一条线(上周)没有数据,全是 null
此时折线图是可以成功的,普通面积图也是成功的,但是面积图使用渐变色(color属性)后会报错:

经查验,只有当所有 value 都是非 number 时就会报错,只要其中有一个
value 是数字,那么就不会报错了

请参考复现链接:

series: [
        {
            name: '会员数-周同比',
            type: 'line',
            data: [
                // 由于需求要求同环比,就会存在,本周有数据
                // 但是上周没数据的情况
                // 即series 中有一个线有数据,有一条线(上周)没有数据,全是 null
                // 此时折线图是可以成功的,但是面积图使用渐变色(color属性)后会报错

                // 经查验,只有当所有 value 都是非 number 时就会报错,只要其中有一个
                // value 是数字,那么就不会报错了
                {
                    value: null
                },
                {
                    value: null
                }
            ],
            areaStyle: {
                // 把这个渐变的 color 属性注释掉就不报错了
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    index: 6,
                    colorStops: [
                        {
                            offset: 0,
                            color: 'rgba(235,83,46, 0.30)'
                        },
                        {
                            offset: 1,
                            color: 'rgba(235,83,46, 0.05)'
                        }
                    ]
                }
            }
        }
    ]

因为这里 getBoundingRect 拿到了 min 和 max 是无穷,导致后面的计算都出错了:

min 和 max 的默认值是否应该取 data[0],如果没有默认为 0 是否更好,现在默认是无穷,导致画图时候出错。如果默认为0,就不画图,也不会出错了。

image

What is expected?

面积图使用颜色渐变后,某个 serie 如果 value 中没有一个是数字,也不要报错。

What is actually happening?

面积图使用颜色渐变后,某个 serie 如果 value 中没有一个是数字,报错了。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions