Chart.js: set specific numbers in y-axis

👍:1

Use the ticks.callback property in options.scales.yAxes along with Javascript’s Number.toExponential.

For example:

{
  type: 'line',
  data: {
    labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
    datasets: [{
      label: 'Data',
      data: [93000, -292768, -172234, -836236, 743553, 95348, 453460],
      fill: false,
    }, ],
  },
  options: {
    scales: {
      yAxes: [{
        ticks: {
          callback: function(val) {
            return val.toExponential()
          }
        }
      }]
    }
  },
}

chart.js with scientific notation

Leave a comment