sgratzl / chartjs-chart-boxplot

Chart.js Box Plots and Violin Plot Charts
https://www.sgratzl.com/chartjs-chart-boxplot/
MIT License
101 stars 23 forks source link

Boxplot overlaps with other chart types (ie. bar) by default - how to change that so the different types are side by side? #100

Closed sqmch closed 3 weeks ago

sqmch commented 5 months ago

Hi there,

By default, chartjs behaves so that if you have multiple datasets with the same chart types (such as bar and bar, or boxplot and boxplot), they divide the category space between them and appear side by side. Boxplot + boxplot also behaves that way, however I'm building something that allows the addition of various datasets with different chart types and am having an issue where the boxplot overlaps bar charts instead of them being side by side.

I saw in the docs an example of the same behaviour, so it seems that it is perhaps intended, however I'd like to figure out how to make for example a bar and a boxplot appear side by side instead of overlapping. Could you point me in the right direction?

Example of how two datasets with type "bar" automatically appear side by side (desired behavior with boxplot and bar):

Example 1

Current behavior with boxplot and bar

Example 2

sgratzl commented 4 months ago

I'm not sure whether this is possible. The grouped bar chart is handled by a single BarController, while here there are two controllers in place. You might be able to play with barPercentage to make the bar and boxplot smaller and then find a way to shift one to the left and the other to the right.