[Chartjs]-Dynamic colours in chartJS based on entries in the array

1👍

Change:

backgroundColor: backgroundColor[x],

to:

backgroundColor: backgroundColor,

Result:

Result of code change

Why does this work?

The backgroundColor property can be specified in a number of ways. Typically it’s set to a string, e.g. #abcdef but it can also be set to an array. In this case Chart.js itself will pick the colour from the array based on the index of the data point it is drawing.

Leave a comment