1๐
โ
You can define array where colors are values and good, bad and normal are keys, see next:
let chartColors = [];
chartColors['good'] = 'green';
chartColors['bad'] = 'red';
chartColors['normal'] = 'yellow';
Then the next step would be to add new array variable where you will push on the same way as you have done for labels:
someColorVar.push(chartColors[key]);
Then replace bgcolor
with someColorVar
.
Source:stackexchange.com