c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.35k stars 1.39k forks source link

Totals on stacked bar chart #984

Open philipcdavis opened 9 years ago

philipcdavis commented 9 years ago

It would be nice to be able to add totals as a data label to stacked bar charts and to their corresponding tool tips. Something like this.

This might require additional design decisions like exposing the ability to center data labels within bars charts as well.

masayuki0812 commented 9 years ago

Yeah, looks nice. Let me mark as enhancement and plugin candidate. Thanks!

avoliva commented 8 years ago

Was this ever implemented?

smartameer commented 8 years ago

Is it possible to show only the total instead of cluttering all values? Lets say my stacked bar values are [0, 1, 2, 500] and in this case text labels overlap each other for 0, 1, 2 with formatting like 'n degree' in rotated axis graph. Is it possible to sum everything and show just one at the top. While selecting label we will pass data-n id as array to consider for sum because graph wont know for which stacked bar it has to show sum, in case of multiple stacked bars.

nbpalomino commented 8 years ago

Bump...

Some news about this?

johnnymetz commented 6 years ago

+1 showing the total on top of the stacked bar chart would be very useful

ArtyomMinsk commented 6 years ago

Any updates on showing total on the top?

n2lose commented 6 years ago

Any news about the optional display text label center in the bar? I got same problem.

tvw commented 6 years ago

Here a quick solution on how to get totals on stacked bar charts:

You can make a stacked bar chart a combination chart by adding a line into the chart which has as data the totals. Because the line represents the totals, it sits exactly on top of the bars, because the stack size is the sum=total. Now we use CSS to remove the line, because you want only see the labels and in order to avoid overlapping labels, we move the labels of the total line a little bit up via CSS. That's it.

Here is a fiddle, which shows the result: https://jsfiddle.net/thomasw/t2aj7xsL/20/

guptavijay208 commented 5 years ago

Any updates on showing total on the top, I also need this feature urgently?

Zenthae commented 3 years ago

sorry to dig out such an old subject but any news about it ? i do need this feature.

apolinario commented 3 years ago

While this does not get implemented, the person that made this fiddle hacked their way to make it work, might be useful for someone else as it was for me: https://jsfiddle.net/Dimmy/d5sxjng2/6/