score:14

Accepted answer

replace your tick­'s usercallback function with the following ...

usercallback: function(item, index) {
   if (!(index % 4)) return item;
}

basically, you don't need to return any empty string for the label that you wish to hide. if you do not return anything (for the label you don't want), it won't draw any tick (as well as gridline) for that label.

ᴅᴇᴍᴏ

var ctx = document.getelementbyid("mychart").getcontext('2d');
var mychart = new chart(ctx, {
   type: 'line',
   data: {
      labels: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sept'],
      datasets: [{
         label: 'standard rating',
         data: [1, 2, 3, 4, 5, 6, 7, 8, 9],
         backgroundcolor: 'rgba(209, 230, 245, 0.5)',
         bordercolor: 'rgba(56, 163, 236, 1)',
         borderwidth: 1
      }]
   },
   options: {
      responsive: false,
      tooltips: {
         mode: 'label',
         intersect: false
      },
      scales: {
         xaxes: [{
            ticks: {
               usercallback: function(item, index) {
                  if (!(index % 4)) return item;
               },
               autoskip: false
            }
         }],
         yaxes: [{
            ticks: {
               beginatzero: true
            }
         }]
      }
   }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.5.0/chart.min.js"></script>
<canvas id="mychart" width="350" height="200"></canvas>


Related Query