Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

配置项series.data数组里如果同时存在null和对象,将会报错Cannot read property 'selected' of null #14293

Closed
lvding opened this issue Feb 19, 2021 · 5 comments · Fixed by #14413
Labels
bug difficulty: easy Issues that can be fixed more easily than the average.
Milestone

Comments

@lvding
Copy link

lvding commented Feb 19, 2021

Version

5.0.2

Steps to reproduce

非连续的折线图/柱状图,在3.x和4.x版本时,
series.data可以用类似[null,{value:3},{value:4},null]这样的数组呈现,而在5.x版本时候必须使用[{value:null},{value:3},{value:4},{value:null}]
否则将会报错Cannot read property 'selected' of null

What is expected?

正常呈现非连续的折线图

What is actually happening?

报错Cannot read property 'selected' of null

@echarts-bot
Copy link

echarts-bot bot commented Feb 19, 2021

Hi! We've received your issue and please be patient to get responded. 🎉
The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that you have posted enough image to demo your request. You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org. Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe our mailing list.

Have a nice day! 🍵

@echarts-bot echarts-bot bot added bug en This issue is in English pending We are not sure about whether this is a bug/new feature. waiting-for: community labels Feb 19, 2021
@pissang pissang removed pending We are not sure about whether this is a bug/new feature. waiting-for: community labels Feb 19, 2021
@pissang pissang added this to the 5.1.0 milestone Feb 19, 2021
@plainheart plainheart removed the en This issue is in English label Feb 19, 2021
@pissang pissang added the difficulty: easy Issues that can be fixed more easily than the average. label Mar 1, 2021
@echarts-bot
Copy link

echarts-bot bot commented Mar 1, 2021

This issue is labeled with difficulty: easy.
@lvding Would you like to debug it by yourself? This is a quicker way to get your problem fixed. Or you may wait for the community to fix.

Please have a look at How to debug ECharts if you'd like to give a try. 🤓

@leosxie
Copy link
Contributor

leosxie commented Mar 3, 2021

i will try to pr this issue

@wf123537200 wf123537200 self-assigned this Mar 3, 2021
@jonavila
Copy link
Contributor

jonavila commented Mar 4, 2021

I ran into this issue in 5.x and I believe it's caused by this method of Series.ts

private _initSelectedMapFromData(data: List) {
        // Ignore select info in data if selectedMap exists.
        // NOTE It's only for legacy usage. edge data is not supported.
        if (this.option.selectedMap) {
            return;
        }

        const dataIndices: number[] = [];
        if (data.hasItemOption) {
            data.each(function (idx) {
                const rawItem = data.getRawDataItem(idx);
                if (typeof rawItem === 'object'
                    && (rawItem as OptionDataItemObject<unknown>).selected
                ) {
                    dataIndices.push(idx);
                }
            });
        }

        if (dataIndices.length > 0) {
            this._innerSelect(data, dataIndices);
        }
    }
    

You can see how it fails if rawItem is null because typeof null === 'object'.

Using undefined in the value instead of null works for me as workaround.

@plainheart
Copy link
Member

Great! Like #14404, y'all got the focus of this error. Any contribution will be much appreciated!

@wf123537200 wf123537200 removed their assignment Mar 8, 2021
@wf123537200 wf123537200 linked a pull request Mar 8, 2021 that will close this issue
5 tasks
pissang pushed a commit that referenced this issue Mar 8, 2021
* fix(series): fix series data type judgment bug. close #14293

* fix(series): fix series data type judgment bug. close #14293

* fix(style): change code style

* fix(remove files): remove history files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug difficulty: easy Issues that can be fixed more easily than the average.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants