Skip to content

fix(candlestick/boxplot): accept null and undefined data items. - #21734

Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
apache:masterfrom
SEPURI-SAI-KRISHNA:fix/whiskerbox-empty-value
Open

fix(candlestick/boxplot): accept null and undefined data items.#21734
SEPURI-SAI-KRISHNA wants to merge 1 commit into
apache:masterfrom
SEPURI-SAI-KRISHNA:fix/whiskerbox-empty-value

Conversation

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Stops candlestick and boxplot from throwing when a data item is an empty value (null / undefined).

Fixed issues

Details

Before: What was the problem?

Empty values are documented as '-', null, undefined or NaN, and every other series treats them interchangeably. For candlestick and boxplot only '-' worked — null and undefined threw before anything was rendered:

option = {
    xAxis: {type: 'category', data: ['d1', 'd2', 'd3']},
    yAxis: {type: 'value'},
    series: [{
        type: 'candlestick',
        // a trading halt / market holiday in the middle of the series
        data: [[20, 30, 10, 35], null, [25, 35, 15, 40]]
    }]
};
TypeError: Cannot read properties of null (reading 'value')
    at src/chart/helper/whiskerBoxCommon.ts:133
    at WhiskerBoxCommonMixin.getInitialData
    at CandlestickSeriesModel.init
    ...
    at ECharts.setOption

Both series share WhiskerBoxCommonMixin#getInitialData. When the base axis is a category axis, it walks the raw data to prepend the ordinal index to each item, and the second branch dereferences item without checking that it exists:

zrUtil.each(data, function (item, index) {
    let newItem;
    if (zrUtil.isArray(item)) {
        // ...
    }
    else if (zrUtil.isArray(item.value)) {   // <- throws when item is null/undefined
        // ...
    }
    else {
        newItem = item;
    }
    newOptionData.push(newItem);
});

'-' survives only because a string has no value property; null and undefined cannot be read at all. The throw happens inside setOption, so it takes down the whole chart rather than just the one item — a real problem for financial charts, where gaps in an OHLC series are routine.

After: How does it behave after the fixing?

The branch now checks that item exists before reading item.value, so an empty item falls through to the existing else and is passed along untouched — exactly the path '-' already takes.

The gap becomes an empty data item that is not drawn, and, importantly, the items after it keep their correct ordinal index (the index is derived from the loop position, not from a running counter), so the series stays aligned with the category axis.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

Added test/ut/spec/series/whiskerBoxEmptyValue.test.ts: null / undefined / '-'
items for both candlestick and boxplot, plus a case asserting that the item after
a gap still maps to the third category and keeps its values.

The '-' cases pass both before and after, and are kept as controls showing the
inconsistency this PR removes. The null / undefined cases fail on master with
TypeError: Cannot read properties of null (reading 'value').

npm run test, npx tsc --noEmit and eslint on the changed file all pass.

Merging options

  • Please squash the commits into a single one when merging.

Other information

This touches src/chart/helper/whiskerBoxCommon.ts, which #21727 also modifies, but
the two changes are in different functions and do not overlap.

@echarts-bot

echarts-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant