score:0

Accepted answer

you will have to update to v3 of the lib, then you can make use of the scriptable options like this:

  options: {
    scales: {
      y: {
        ticks: {
          color: (tick) => (tick.tick.value < 0 ? 'red' : tick.tick.value > 0 ? 'green' : '#666')
        }
      }
    }
  }

live example:

var options = {
  type: 'line',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
      label: '# of votes',
      data: [-12, 19, 3, -5, 2, 3],
      borderwidth: 1,
      bordercolor: 'red',
      backgroundcolor: 'red'
    }]
  },
  options: {
    scales: {
      y: {
        ticks: {
          color: (tick) => (tick.tick.value < 0 ? 'red' : tick.tick.value > 0 ? 'green' : '#666')
        }
      }
    }
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
    <canvas id="chartjscontainer" width="600" height="400"></canvas>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.3.0/chart.js"></script>
</body>


Related Query

More Query from same tag