Chartjs-Chart.js how to force min and max y axis values

1👍

I suppose you’re using Chart.js version 3.

According to the 3.x Migration Guide, the following relevant changes have been made since v2.

  • scales.[x/y]Axes.ticks.beginAtZero was renamed to scales[id].beginAtZero
  • scales.[x/y]Axes.ticks.max was renamed to scales[id].max
  • scales.[x/y]Axes.ticks.min was renamed to scales[id].min
  • scales.[x/y]Axes.ticks.suggestedMax was renamed to scales[id].suggestedMax
  • scales.[x/y]Axes.ticks.suggestedMin was renamed to scales[id].suggestedMin

Therefore, instead of…

scales: {
  yAxes: [{
    ticks: {
      beginAtZero: true,
      suggestedMax: 100
    }
  }
}

…you now have to define:

scales: {
  y: {
    beginAtZero: true,
    suggestedMax: 100
  }
}     

Leave a comment