Skip to content

fix(bar): create the background for the new index when the old bar had none - #21865

Open
Xnadir wants to merge 1 commit into
apache:masterfrom
Xnadir:fix/bar-background-update
Open

Xnadir wants to merge 1 commit into
apache:masterfrom
Xnadir:fix/bar-background-update

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 23, 2026

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Creates a bar's background for the new data index when the old bar had none, so turning showBackground on in an update no longer throws or leaves bars without a background.

Fixed issues

Details

Before: What was the problem?

In BarView._renderNormal, the update branch of the data diff handled a missing background with createBackground(oldIndex). That function lays out the given index in the new data, so:

  • With fewer bars after the update (the issue's "All products" → "Top 3"), the old index has no layout. createBackground returned null, and updateProps(null, …) threw Cannot read properties of null (reading 'stopAnimation'). The chart was left half-updated: no tracks, one bar missing, an extra bar drawn.
  • When some old bars had a background and others did not, oldBgEls.length !== 0 sent the code to oldBgEls[oldIndex], which could be undefined.

After: How does it behave after the fixing?

The update branch reuses oldBgEls[oldIndex] when it exists. Otherwise it creates the background for newIndex, and it skips the background when the bar has no layout.

New case in test/ut/spec/series/bar.test.ts: five bars without background, then the top three with showBackground: true. The update must not throw, and there must be three bars, each with a background. On master it fails with the TypeError.

Ran locally:

  • npx jest --config test/ut/jest.config.cjs test/ut/spec/series test/ut/spec/component test/ut/spec/api (46 passed);
  • eslint on the changed files;
  • tsc -p tsconfig.json --noEmit.

Document Info

  • This PR doesn't relate to document changes

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

N.A.

Merging options

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

Other information

This change was written with the help of Claude Code (AI). I reviewed it and ran the tests above.

🤖 Generated with Claude Code

…d none. close apache#21862

When showBackground was turned on in an update, the update branch of the
data diff created the background with the old data index, laid out in
the new data. With fewer bars that index has no layout, so it returned
null and updateProps threw "Cannot read properties of null (reading
'stopAnimation')", leaving the chart half-updated. When some old bars
had backgrounds and others not, it read a missing one.

The update branch now reuses the old background when there is one and
otherwise creates one for the new index, and skips it when the bar has
no layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echarts-bot

echarts-bot Bot commented Nov 23, 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.

This branch has not been deployed

No deployments
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