0👍
✅
barChartData
is an array of ChartDataSets
that contains a single element. Therefore, to make it work, you could change your code as follows:
[colors]="barChartData[0].data.map(v => v > 0 ? barChartColors[0] : barChartColors[1])"
or more compact…
[colors]="barChartData[0].data.map(v => barChartColors[v > 0 ? 0 : 1])"
This code uses
Array.map()
, on thedata
array insideChartDataSets
. It returns a newarray
with the appropriate color for each value.
Source:stackexchange.com