Edu Felipe
Edu Felipe

Reputation: 10387

Unable to make y-axis to begin at zero on Charts.js v2.1.4

When using the following code to generate a chart, I am not able to set the scale to begin at zero, even setting that option.

Here is the code (JSFiddle)

var simpleChart = new Chart(document.getElementById('chart'), {
    type: 'bar',
    data: {
      labels: ['Online', 'Offline'],
      datasets: [{
        label: "# of servers",
        data: [1, 7],
        backgroundColor: [
            '#009245',
            '#c02a31'
        ]
      }]
    },
    options: {
        title: {
            display: false
        },
        scales: {
            yAxes: [{
                beginAtZero: true
            }]
        }
    }
});

Is this a bug? What should I do to be able to set the scale to really start at 0?

Also, how can I disable that "# of servers" label from being rendered?

Upvotes: 4

Views: 8673

Answers (1)

Tetzlove
Tetzlove

Reputation: 176

I had the same problems. You have to define "ticks" within the yAxes-definition:

scales: {
          yAxes: [{
            ticks: {
                beginAtZero: true
            }
          }]
}

Updated fiddle: https://jsfiddle.net/r90Ljzvo/5/

Upvotes: 15

Related Questions