[Chartjs]-How to make integer scale in Chartjs

21๐Ÿ‘

โœ…

The linked question is for Chart.js version 1.x. For the new version you need to use the ticks option. See http://www.chartjs.org/docs/#scales

   ...
   xAxes: [{
      ticks: {
        min: 0,
        stepSize: 1,
        max: 4
      },
      ...

Fiddle โ€“ https://jsfiddle.net/jkufz1b9/

0๐Ÿ‘

For anyone coming across this nowadays (ChartJS 4+), if you want to keep the automatic stepSize and not define it statically, you can simply use the precision option on the ticks to define to how many decimal places the ticks will be rounded. Use 0 for an integer scale:

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

Linear Axis Tick Options

Leave a comment