score:2

Accepted answer

you can use the object notation to achieve this by telling to which x label chart.js has to link the value so you can skip some labels.

example:

var options = {
  type: 'line',
  data: {
    labels: [2019, 2020, 2021, 2022],
    datasets: [{
      label: '# of votes',
      data: [{
        x: 2019,
        y: 100
      }, {
        x: 2021,
        y: 200
      }, {
        x: 2022,
        y: 100
      }],
      bordercolor: 'pink',
      backgroundcolor: 'red',
      radius: 5
    }]
  },
  options: {
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
  <canvas id="chartjscontainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.5.0/chart.js"></script>
</body>


Related Query

More Query from same tag