SEPURI-SAI-KRISHNA opened a new pull request, #21734:
URL: https://github.com/apache/echarts/pull/21734

   ## Brief Information
   
   This pull request is in the type of:
   
   - [x] 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
   
   <!-- No existing issue; found while auditing empty-value handling across 
series. -->
   
   
   ## 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:
   
   ```js
   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:
   
   ```js
   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.
   
   - [x] 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
   
   - [x] 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to