I'm trying to set colors for charts made using chart.js library.
I need a specific color for each data label. but when data of specific labels is zero colors get confused :(.
it looks like the library drops zero-data labels and labels colored differently.
For example, when data is:
- colors:
green
,red
,yellow
, - labels:
passed
,failed
,in progress
- data:
0
,5
,80
passed labeled data will be skipped as its value is zero, so failed labeled data gets the first color: green
, and so on.
How can I force colors matching?
Current code:
html:
<canvas baseChart height="150px" width="150px" [data]="graphData" [labels]="graphLabels" [colors]="graphColors"
[options]="graphOptions" [legend]="false" [chartType]="'doughnut'">
</canvas>
TypeScript:
this.graphData = this.data.map(r => r.cnt);
this.graphLabels = this.data.map(r => r.city);
this.graphOptions = {
layout: {padding: 20},
cutoutPrecentage: 90,
legend: {display: false}
};
thanks!