yqtian-se opened a new issue, #21862: URL: https://github.com/apache/echarts/issues/21862
### Version 6.1.0 (also current `master` and 5.6.0) ### Link to Minimal Reproduction https://echarts.apache.org/examples/en/editor.html?code=ZVJNj9owEL3nVzxxSZDSLFv6sQJxYKl63R64rTiYYIhLYlu2sxCh_PeObUIjraIoE_vNvHkz7-kJf4w6tKWDZTW3uAhXgeFD8Au0KM_cFJis6xo6wuwEwhJA10xI7JlBWTHjioQqTbZKYz6BrdTFQsm6g6s49ty6R3o-MJwM7yi_PJ-MauUhlGK-sjN0iFbDqZDesKto2qZIPggRm1zhhrXWFC7w7WuOVybpoZ-f33NsKm6M8FfzWY5fzPnw5SXHb3Gi6Mcz-mWSHFtZOqEklT_zN-3DzIue4pYAnkqyJlC97f_y0hVn3tks0E-XhBBHBDxWqxVSp_Q8jal4JIZvYZVx2YMtYzn2BIThrjUy6nnf7_DlHrLdEv20sLUoeUb9zwNbT-89I3Jc11dBYm5wneYLpCXJPCnTpTkOzLHFvYk-D-huQNMsF3iezYYLy-Ok3mNVDOVoGWlEEIa2-frY0yJa47_qATaiLRqmR5LlJ70yiAyJ_c7LWyZ9kqiwBRrcaCUpq-uURuDttSUztNRx8KUd3FbQOTmyJCDZxZDzghU3TErliJYdvPc0N46UQh0hW0Jm_kLIE1JLKtZSNMzzpdNJkVjutqLhqh3vLS636TbB7QS5NzjuNbqAuu1zP-TZdPkP&enc=deflate ### Steps to Reproduce A sales chart with a view picker: "All products" is a plain bar chart, "Top 3" shows only the three best products with a grey background bar as a track. Going from "All products" to "Top 3" throws: ```js // Product sales with a view picker. "All products" is a plain bar chart. // "Top 3" shows only the best products, with a grey background bar as a track up to the maximum. var sales = { Apples: 42, Bananas: 75, Cherries: 30, Dates: 88, Figs: 61 }; function makeOption(view) { var names = Object.keys(sales); if (view === 'top3') { names = names.sort(function (a, b) { return sales[b] - sales[a]; }).slice(0, 3); } return { xAxis: { type: 'category', data: names }, yAxis: { max: 100 }, series: [{ type: 'bar', showBackground: view === 'top3', data: names.map(function (n) { return sales[n]; }) }] }; } option = makeOption('all'); // The user picks "Top 3". This call throws // "Cannot read properties of null (reading 'stopAnimation')". setTimeout(function () { myChart.setOption(makeOption('top3')); }, 1000); ``` <!-- screenshot: browser-canvas-master.png (left: after picking Top 3, right: Top 3 when the page starts with it) --> Smaller case, removing a category while turning the background on: ```js option = { xAxis: { data: ['Mon', 'Tue', 'Wed'] }, yAxis: {}, series: [{ type: 'bar', data: [1, 2, 3] }] }; setTimeout(function () { // TypeError: Cannot read properties of null (reading 'stopAnimation') myChart.setOption({ xAxis: { data: ['Tue', 'Wed'] }, series: [{ showBackground: true, data: [2, 3] }] }); }, 1000); ``` Adding a category in front instead does not throw, but the bar for `Mon` gets no background, and setting the same option once more throws `Cannot read properties of undefined (reading 'useStyle')`: ```js option = { xAxis: { data: ['Mon', 'Tue'] }, yAxis: { max: 4 }, series: [{ type: 'bar', data: [1, 2] }] }; setTimeout(function () { // Add a category in front and turn the background on in the same call. // The bar for 'Mon' has no background. myChart.setOption({ xAxis: { data: ['Sun', 'Mon', 'Tue'] }, series: [{ showBackground: true, data: [3, 1, 2] }] }); }, 1000); ``` ### Current Behavior Picking "Top 3" throws `Cannot read properties of null (reading 'stopAnimation')` and leaves the chart half-updated: no background tracks, one bar missing and an extra bar drawn. On 5.6.0 the message is `Cannot read properties of undefined (reading 'width')`. When the update does not throw, some bars are drawn without their background. ### Expected Behavior No error; each of the three bars has its grey track. ### Environment - OS: any - Browser: any (canvas and SVG renderer) - Framework: none ### Any additional comments? In `BarView._renderNormal`, when the previous render had no backgrounds, the `update` callback of `data.diff(oldData)` calls `createBackground(oldIndex)`. That lays out and stores the background under the old data index instead of the new one, so when the indexes differ some backgrounds are overwritten or left out, and the next update reads a missing one. Using `newIndex` there fixes it. This line was added in #13084 (fix for #13009). -- 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]
