-
Notifications
You must be signed in to change notification settings - Fork 19.7k
feat: support stackPercent
for normalized stacking
#20910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for your contribution! Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to support normalized stacking, it should not use stackStrategy because this concept is for deciding whether to stack positive/negative values. You should probably need another new option for this feature.
Stacking by percentage can be supported with current ECharts with a little hacking so it should be nice to have this feature to make the option more intuitive. Thanks for your contribution.
And I'm not sure how to let the axis know that this is a normalized series and should use |
Yeah this makes sense, I found an older discussion on this topic here where you proposed: I went ahead and made that change in this commit but open to any other ideas! |
Agreed this seems difficult, I think starting with requiring the custom formatter can work (I can point this out in docs / create a new example). I played around with setting the axisLabel formatter automatically (when one isn't already defined) in this branch, but that doesn't seem like a great solution EDIT: Added examples in percent-stack.html here |
stackPercent
for normalized stacking
Maybe you should set the axis max to 100%? |
Yeah good call, it is a little awkward to do this for similar reasons as here but I'll look into it more. This PR is already pretty large, @Ovilia would you prefer I open a separate PR to adjust the axis max / formatter or keep adding to this one? |
Hi, based on this PR. |
Do you happen to have any updates here? wish to see this pr be merged, it's beneficial |
Raw value is still included and the normalized value was added in series label and tooltip formatter as echarts/test/percent-stack.html Lines 182 to 187 in 1d0603f
![]() |
Glad to hear you find it useful! I just opened a docs PR so I'm waiting on more feedback on the initial implementation and the new option name Hoping to add enhancements like appending '%' to series label / yAxis.axisLabel and setting yAxis.max to 100 automatically in a later PR (since they can be set explicitly as shown in percent-stack.html example) |
Brief Information
This pull request is in the type of:
What does this PR do?
Adds support for
stackPercent: boolean
, which normalizes all stacked series values into percentages per category index (so the stacked total always adds up to 100%).Fixed issues
Details
Before: What was the problem?
No built-in way to compute percent-stacked values across a stack group without pre-processing data (see bar-stack-normalization example).
After: How does it behave after the fixing?
When
stackPercent: true
is set on a stacked series, values are automatically normalized to percentages per category. Tooltip shows both raw value and percentage.With formatters:

Document Info
One of the following should be checked.
Misc
ZRender Changes
Related test cases or examples to use the new APIs
bar-stack-normalization
Others
Merging options
Other information