Chartjs-Why ChartJS's Bar Chart does not render bar for a specific value?

2👍

You need to use beginAtZero: true in yAxes.ticks for both charts which will allow you to specify that the scale starts at 0.

var options = {
  type: 'bar',
  data: {
    labels: ["Jan", "Feb", "Mar", "Apr", "May", "June", "July"],
    datasets: [{
      label: '# of Votes',
      data: [9.24, 6.28, 5.65, 6.74, 4.01, 17.15, 3],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      yAxes: [{
        ticks: {
          reverse: false,
          beginAtZero: true
        },
      }],
      xAxes: [{}]
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
canvas {
  background-color: #eee;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>

<body>
  <canvas id="chartJSContainer" width="600" height="200"></canvas>
</body>
var options = {
  type: 'bar',
  data: {
    labels: ["Jan", "Feb", "Mar", "Apr", "May", "June", "July"],
    datasets: [{
      label: '# of Votes',
      data: [9.24, 6.28, 5.65, 6.74, 4.01, 17.15, 4.01],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      yAxes: [{
        ticks: {
          reverse: false,
          beginAtZero: true
        },
      }],
      xAxes: [{}]
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
canvas {
  background-color: #eee;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>

<body>
  <canvas id="chartJSContainer" width="600" height="200"></canvas>
</body>

Leave a comment