Chartjs-ChartJS, make the bars show correct percentage?

1๐Ÿ‘

โœ…

I think your issue is with the following line:

const otherDatasetIndex = ctx.datasetIndex === 0 ? 1 : 0;

This will always use the first dataset to compare against. There are 6 total datasets and you want compare sets of two. The below code should fix this.

const otherDatasetIndex = ctx.datasetIndex % 2 === 0 ? ctx.datasetIndex + 1 : ctx.datasetIndex - 1;

This will compare all even datasets with the odd dataset just after it and all odd data sets with the even dataset coming before it in the array.

Leave a comment