Chartjs-In chart.js bar chart, how do I label each bar within a category?

0๐Ÿ‘

โœ…

1) set 2 labels for each sub category within a category
2) for each bar within a category, add the value if it matches the label position, then add 0 to the value for the alternative sub category not matching the label position

This will produce a bar chart where each category only has 1 bar of a colour gradient unique to that subcategory.

You may need to play around with the bar sizing, since I only have 2 sub categories, I set

scales: {
        xAxes: [{
            barPercentage: 8,
            categoryPercentage: 0.1
        }]
    }
}

and it aligned with the category label closely enough for me.

Leave a comment