Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Combining a stacked and unstacked chart

Open Roarster opened this issue 10 years ago • 4 comments

I'm trying to create a v2.0 chart which has a stacked bar chart and an unstacked line chart on the same chart but at the moment all I've managed to create is a chart where both datasets are stacked. This seems to be because the stacked option is on the scale rather than the dataset. Here's an example showing both sets stacked:

https://jsfiddle.net/45wpjtsu/1/

I've worked around this for now by creating my own line chart type and scale that basically ignore the stacking for the line chart but I wonder if there's a better way to do this?

Roarster avatar Feb 01 '16 12:02 Roarster

As the stack option is applied to the yaxes, I would advice to create a second vertical axe that would not be stacked and to associate the line charts to this new axe.

V2 supports multiple axes, but I sadly did not got time to learn howto. I hope the documentation could guide you through. http://nnnick.github.io/Chart.js/docs-v2/#scales

Dergonic avatar Feb 01 '16 12:02 Dergonic

I tried this but I ended up with 2 axes on the chart which wasn't all that user friendly. Ideally I'd like a single set of vertical axes with a scale chosen to match both sets of data. Any idea if this is possible?

Roarster avatar Feb 01 '16 13:02 Roarster

Closing. The two axis solution is the recommended solution at this point. You could figure out what the axis max will be ahead of time and set that as the suggestedMax on both axes to ensure that they have the same scaling.

Then hide the 2nd axis and it will work as expected.

etimberg avatar Sep 14 '16 00:09 etimberg

It would be really nice if we didn't have to manually calculate the scale for the axis. This seems more like a workaround than a solution that should be recommended.

Storyyeller avatar Jan 22 '18 18:01 Storyyeller