[Chartjs]-Chart.js beginAtZero doesn't work

2👍

It looks like you are using Chart.js v1 instead of v2.

First, update your the Chart.js code to v2, preferably the latest version.

Then, change the following code:

var barGraph = new Chart(ctx, {
    type: 'bar',
    data: chartdata
    options: options
});

to:

var barGraph = Chart.Bar(ctx, {
  data: chartdata,
  options: options
});

beginAtZero: true should then work as expected.

Working JSFiddle: https://jsfiddle.net/ko54hp6n/


For an alternative to beginAtZero: true, you can also use the min: 0 ticks configuration option to start the bar axis at zero:

var options = {
  scales: {
    yAxes: [{
      ticks: {
        min: 0
      }
    }]
  }
}

Working JSFiddle: https://jsfiddle.net/ko54hp6n/1/

Leave a comment