[Chartjs]-How to Add minor/major configs to Ticks

0👍

I was able to do it.

Follow the below steps:

  1. Use chart.js version 2.7.3 from https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js

  2. Find the code helpers.each(itemsToDraw, function(itemToDraw) { at line 7899 and replace it with helpers.each(itemsToDraw, function (itemToDraw, index) { in chart.js

  3. 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;
}
  1. 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'],
                 }
        }]

The output I got

Leave a comment