0👍
I was able to do it.
Follow the below steps:
-
Use chart.js version 2.7.3 from
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js
-
Find the code helpers.each(itemsToDraw, function(itemToDraw) { at line 7899 and replace it with
helpers.each(itemsToDraw, function (itemToDraw, index) {
in chart.js -
Find the code
context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
at line 7931 and replace it with code ->
if (Object.prototype.toString.call(tickFontColor) === '[object Array]') {
context.fillStyle = itemToDraw.major ? majorTickFontColor[index] : tickFontColor[index];
} else {
context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
}
- Pass the multiple colors in the options, the number of colors should match the xAxis label count.
xAxes: [{
ticks: {
fontColor: ['red', 'grey', 'blue', 'black', 'orange', 'green'],
}
}]
Source:stackexchange.com