[Chartjs]-Chart js chart bar chart not showing data from 0

0👍

try option ticks.beginAtZero, see following working snippet…

$(document).ready(function() {
  var chartdata = {
    labels: ['a', 'b'],
    datasets: [{
      label: 'Student Marks',
      backgroundColor: '#49e2ff',
      borderColor: '#46d5f1',
      hoverBackgroundColor: '#CCCCCC',
      hoverBorderColor: '#666666',
      data: [3, 7]
    }]
  };

  var graphTarget = $("#graphCanvas");

  var barGraph = new Chart(graphTarget, {
    type: 'bar',
    data: chartdata,
    options: {
      scales: {
        yAxes: [{
          ticks: {
            beginAtZero: true
          }
        }]
      }
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="graphCanvas"></canvas>

Leave a comment