3👍
✅
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>
Source:stackexchange.com