score:2

Accepted answer

you can add autoskip: false to the yaxis.ticks configuration as follows

ticks: {
  autoskip: false,

if autoskip is true (default), chart.js automatically calculates how many labels can be shown and hides labels accordingly. turn autoskip off to show all labels no matter what.

new chart(document.getelementbyid('mychart'), {
  type: 'bar',
  data: {
    labels: ["jan", "feb", "mar", "apr", "may"],
    datasets: [{
      label: 'events',
      data: [0, 5, 6, 0, 0],
      backgroundcolor: "#2dce89"
    }]
  },
  options: {
    responsive: true,
    legend: {
      display: false
    },
    scales: {
      yaxes: [{
        display: true,
        ticks: {
          autoskip: false,
          beginatzero: true,
          stepsize: 2,
          max: 30
        }
      }]
    }
  }
});
canvas {
  max-width: 260px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.3/chart.min.js"></script>
<canvas id="mychart" height="200"></canvas>


Related Query

More Query from same tag