echarts icon indicating copy to clipboard operation
echarts copied to clipboard

[Feature] Support for 100% stacked charts

Open Shaq76 opened this issue 3 years ago • 7 comments

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: https://github.com/apache/echarts/issues/8785

Apache superset has already implemented this feature, see here: (in the superset code it's called a 'contribution') https://github.com/apache/superset/issues/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%' }

Shaq76 avatar Jun 07 '22 12:06 Shaq76

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 avatar Jun 08 '22 02:06 Ovilia

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

Shaq76 avatar Jun 08 '22 08:06 Shaq76

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

Ovilia avatar Jun 08 '22 09:06 Ovilia

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

Shaq76 avatar Jun 21 '22 16:06 Shaq76

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

Creatium avatar Nov 07 '22 13:11 Creatium

Hi. is this still updated

LeoDiep avatar Sep 08 '23 04:09 LeoDiep

+1, Please implement this

108EAA0A avatar Feb 22 '24 08:02 108EAA0A

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 avatar Feb 26 '24 07:02 Ovilia

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?

Shaq76 avatar Feb 26 '24 10:02 Shaq76