https://i.sstatic.net/M4FWH.pngI am currently attempting to set colors for bars in a bar graph based on the range of values they represent.
TS
public barChartData: any[];
public chartColors: any[];
value = [] // The array contains values retrieved from the database, such as [3.5, 2.5, 1.5, 6.5, 6, 1, 6.5, 3.5, 5.5]
this.barChartData = [{
data: this.value,
label: 'Insulin'
}]
var l = this.value.length;
for (var i = 0; i < l; i++) {
if (this.value[i] <= 3) {
this.chartColors = [{
backgroundColor: 'rgba(255, 205, 86, 9)',
borderColor: 'rgba(255, 205, 86, 9)'
}]
} else if (this.value[i] > 3 && this.value[i] <= 6) {
this.chartColors = [{
backgroundColor: 'rgba(255, 99, 132, 62)',
borderColor: 'rgba(255, 99, 132, 62)'
}];
} else if (this.value[i] > 6) {
this.chartColors = [{
backgroundColor: 'rgba(54, 162, 235, -12)',
borderColor: 'rgba(54, 162, 235, -12)'
}];
}
}
This approach is not yielding the desired results. Can anyone provide guidance on the correct method to achieve this?