Skip to content
Advertisement

Different color for each bar in a bar chart; ChartJS

I’m using ChartJS in a project I’m working on and I need a different color for each bar in a Bar Chart.

Here’s an example of the bar chart data set:

JavaScript

Is there any way to paint each bar differently?

Advertisement

Answer

After looking into the Chart.Bar.js file I’ve managed to find the solution. I’ve used this function to generate a random color:

JavaScript

I’ve added it to the end of the file and i called this function right inside the “fillColor:” under

JavaScript

so now it looks like this:

JavaScript

and it works I get different color for each bar.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement