Chartjs-Chartjs stack bar graph color not working

0👍

Each data point needs a background color:

e.g.

{data: [0, 0, 1, 0, 0, 1, 0], label: 'Email Clicks', backgroundColor:[rgb(0, 0, 0), rgb(0, 0, 0), rgb(0, 0, 0), rgb(0, 0, 0), rgb(0, 0, 0), rgb(0, 0, 0)]'}

If you intend to use the same color for each data point, you can just create the array dynamically instead of all that copy and paste.

0👍

Is this ng2-charts?

add this to the canvas tag:

[colors]="barChartColors"

Each element in the barChartColors maps to the same index as an entry in barChartData

You don’t need to put backgroundColor in each barChartData then.

Leave a comment