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?

Edu Felipe
  • 10,197
  • 13
  • 44
  • 41

1 Answers1

15

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/

Tetzlove
  • 176
  • 2
  • 5