[Chartjs]-Reducing Y-axis in chart.js

5👍

You can use the stepSize property of y-axis­ ticks. By setting this property to a value (interval) of 20 will reduce the y-axis­‘s ticks count.

scales: {
   yAxes: [{
      ticks: {
         stepSize: 20
      }
   }]
}

ᴅᴇᴍᴏ

var chart = new Chart(ctx, {
   type: 'line',
   data: {
      labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
      datasets: [{
         label: 'LINE',
         data: [10, 30, 20, 50, 60],
         backgroundColor: 'rgba(0, 119, 290, 0.2)',
         borderColor: 'rgba(0, 119, 290, 0.6)',
         fill: false
      }]
   },
   options: {
      scales: {
         yAxes: [{
            ticks: {
               beginAtZero: true,
               stepSize: 20 //<-- set this
            }
         }]
      }
   }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>

Leave a comment