I have two dataset arrays.
data: [589, 445, 483, 503, 689, 692, 634],
data: [639, 465, 493, 478, 589, 632, 674],
I want to draw every dataset with arrays of color into CSS file.
In my css file, there is :
/* Colors */
.color0 {
background-color: red !important;
}
.color1 {
background-color: lightgray !important;
}
I want to use the colors variable to draw my two array with input color in CSS file. The problem is that the graph bar have black color like what is showing in image as below :
// Color array to draw bar dataset
var colors = ['color0', 'color1'];
var chBar = document.getElementById("chBar");
var chartData = {
// Label of Entity
labels: ["RTI_0;RTI", "RTI_1;RTI", "RTI_2;RTI", "BB_0;BB", "BB_1;BB", "BB_2;BB", "BB_3;BB"],
// Value of percent category RTI|| VSM ...
datasets: [{
data: [589, 445, 483, 503, 689, 692, 634],
backgroundColor: colors[0]
},
{
data: [639, 465, 493, 478, 589, 632, 674],
xAxisID: 'xAxis1',
backgroundColor: colors[1]
}
]
};
if (chBar) {
// new graph
new Chart(chBar, {
type: 'bar',
data: chartData,
options: {
scales: {
xAxes: [{
barPercentage: 0.7,
categoryPercentage: 0.3,
id: 'xAxis1',
type: "category",
ticks: {
callback: function(label) {
var sublabel_x = label.split(";")[0];
var label_p = label.split(";")[1];
return sublabel_x;
}
}
},{
id: 'xAxis2',
type: "category",
gridLines: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
},
ticks: {
callback: function(label) {
var sublabel_x = label.split(";")[0];
var label_p = label.split(";")[1];
if (label_p === "RTI") {
return label_p;
} else {
return label_p;
}
}
}
}
],
yAxes: [{
ticks: {
beginAtZero: false
},
scaleLabel: {
display: true,
labelString: '%'
}
}]
},
legend: {
display: false
}
}
});
}
Please help