feat: support stackPercent for normalized stacking#20910
feat: support stackPercent for normalized stacking#20910sjcobb wants to merge 1 commit intoapache:masterfrom
stackPercent for normalized stacking#20910Conversation
|
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 |
Ovilia
left a comment
There was a problem hiding this comment.
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) |
|
Rebased and fixed all merge conflicts from the stackOrder PR #20998 |

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: trueis 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