Skip to content

Conversation

@Justin-ZS
Copy link
Contributor

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Fix incorrect data label position when bar width/height is 0.
截屏2025-08-22 14 15 30

Fixed issues

Details

Before: What was the problem?

When a bar has zero width or height (data value is 0), the label position calculation for label.position: 'outside' was incorrect, especially when the axis is inverted.
The original logic only checked layout.height >= 0 or layout.width >= 0 without considering axis inversion, causing labels to appear in wrong positions.

After: How does it behave after the fixing?

Added two helper functions getLabelPositionForHorizontal and getLabelPositionForVertical to properly handle label positioning when bar dimensions are zero.
The functions check the value axis's inverse property to determine the correct label position, ensuring labels appear correctly regardless of axis configuration.

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

ZRender Changes

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

Related test cases or examples to use the new APIs

N.A.

Others

Merging options

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

Other information

Modified src/chart/bar/BarView.ts to replace simple ternary operators with smarter function calls that consider axis inversion when determining label positions for zero-dimension bars.

@echarts-bot
Copy link

echarts-bot bot commented Aug 22, 2025

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.

Copy link
Contributor

@Ovilia Ovilia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also depends on label.position?

@Justin-ZS
Copy link
Contributor Author

Justin-ZS commented Aug 22, 2025

Does this also depends on label.position?

Yes. the calculated value is assigned to labelPositionOutside and is only used for position: 'outside'

@Justin-ZS Justin-ZS requested a review from Ovilia August 22, 2025 07:33
@github-actions
Copy link
Contributor

The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-21218@cbf5c62

@Ovilia Ovilia merged commit 8ba89a9 into apache:master Aug 25, 2025
2 checks passed
@echarts-bot
Copy link

echarts-bot bot commented Aug 25, 2025

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

@Ovilia
Copy link
Contributor

Ovilia commented Aug 25, 2025

Thanks for your contribution!

@Ovilia Ovilia added this to the 6.0.1 milestone Aug 25, 2025
@plainheart plainheart changed the title fix(bar): wrong data label position when bar width/height is 0 fix(bar): fix wrong label position when bar width/height is 0 Dec 16, 2025
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.

2 participants