Skip to content

[Feature] Support for 100% stacked charts #17179

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

Closed
Shaq76 opened this issue Jun 7, 2022 · 10 comments
Closed

[Feature] Support for 100% stacked charts #17179

Shaq76 opened this issue Jun 7, 2022 · 10 comments
Labels

Comments

@Shaq76
Copy link

Shaq76 commented Jun 7, 2022

What problem does this feature solve?

I am trying to emulate the functionality provided by Excel and echarts has no native support for 100% stacked charts.
I have tried to work around this by calculating the percentages myself but then you lose the original value tooltip.

There is an existing issue about this here:
#8785

Apache superset has already implemented this feature, see here: (in the superset code it's called a 'contribution')
apache/superset#13580

What does the proposed API look like?

My suggestion is that you extend the 'stack' syntax to support something like this:
stack: { name: 'male', type: '100%' }

@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Jun 7, 2022
@Ovilia
Copy link
Contributor

Ovilia commented Jun 8, 2022

The advised way to do so is to calculate percentage as you said. The tooltip can set formatter or valueFormatter to calculate the original value. If you or anyone from the Apache Superset community wish to implement this in Apache ECharts, we would appreciate it very much. Maybe an option like stackPercent: true should be added.

@Ovilia Ovilia added topic: bar topic: stack and removed pending We are not sure about whether this is a bug/new feature. labels Jun 8, 2022
@Shaq76
Copy link
Author

Shaq76 commented Jun 8, 2022

Hi @Ovilia, I tried implementing the tooltip in valueFormatter but I'm not given the params object (which is available a few levels up the call stack) so the only information I know is the percentage value. If I use the tooltip formatter instead then I lose the nice default tooltip containing the series colour and other information. Thanks for your help :)

@Ovilia
Copy link
Contributor

Ovilia commented Jun 8, 2022

You should probably save the sum to a variable that can be accessed by valueFormatter.

@Shaq76
Copy link
Author

Shaq76 commented Jun 21, 2022

Just a note that this looks similar in implementation to the following PR:
#17086

@Creatium
Copy link

Creatium commented Nov 7, 2022

Hi. Any updates on this? I still see no way to make bar charts stack to 100% easily, without hacking with 0.X values.

@LeoDiep
Copy link

LeoDiep commented Sep 8, 2023

Hi. is this still updated

@108EAA0A
Copy link

+1, Please implement this

@Ovilia
Copy link
Contributor

Ovilia commented Feb 26, 2024

Please checkout https://echarts.apache.org/examples/zh/editor.html?c=bar-stack-normalization and https://echarts.apache.org/examples/zh/editor.html?c=bar-stack-normalization-and-variation

@Ovilia Ovilia closed this as completed Feb 26, 2024
@Shaq76
Copy link
Author

Shaq76 commented Feb 26, 2024

Hi, I have looked at the two examples and these do work around part of the problem, but not fully.
By transforming the incoming data in to percentages we can no longer get access to the original values.
The result is that the tooltip can only show the percentage value, see below.
image
So the problem remains: I want to plot 100% stacked while keeping the source data as the original value?

@sjcobb
Copy link

sjcobb commented Apr 10, 2025

Hi, I have looked at the two examples and these do work around part of the problem, but not fully. By transforming the incoming data in to percentages we can no longer get access to the original values. The result is that the tooltip can only show the percentage value, see below. image So the problem remains: I want to plot 100% stacked while keeping the source data as the original value?

I've opened a PR #20910 to address this by adding stackPercent: boolean, which will show the original value and normalized value (as a percent of the total stack) in the tooltip:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants