[Chartjs]-Charts.js Y-Axis whole Numbers

2๐Ÿ‘

โœ…

Try with this code inside the option section

 scales: {
      yAxes: [{
        ticks: {
          beginAtZero: true,
          callback: function(value) {if (value % 1 === 0) {return value;}}
        }
      }]
    }

10๐Ÿ‘

You can use the stepSize property:

scales: {
  yAxes: [{
    ticks: {
      stepSize: 1
    }
  }]
}

8๐Ÿ‘

A better way to do it which allows for scaling is to use the precision property:

scales: {
    y: {
        ticks: {
            precision: 0
        }
    }
}

This way, if you add a 100 or something, it can increase the step size if needed. It just wonโ€™t even lower it below 1.

Leave a comment