3๐
In the x axis settings you need add :
scales: {
xAxes: [{
bounds: 'ticks',
}]}
Not sure what this changes but it will fix your problem.
- [Chartjs]-Calling a TypeScript function from a Chart.js option callback
- [Chartjs]-Chart.js HTML custom legend issues with doughnut chart
3๐
time: {
round: 'day'
}
solved it for me
0๐
Inside callback you can write a logic to control the number of ticks.
callback(value, index, values){
if(index === 0)
{
return `${value}`
}
}
Hope this might help.
For more information please refer
- [Chartjs]-How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- [Chartjs]-How can I display a set amount of ticks on the Y Axis?
0๐
Chart.js v.4
Utilizing Version 4 of Chart.js, I accomplised this by setting the bounds of the x-axis.
According to the Configuration Options documentation chartjs.org, the default value is โdataโ.
The bounds property controls the scale boundary strategy (bypassed by
min/max options).
- โdataโ: makes sure data are fully visible, labels outside are removed
- โticksโ: makes sure ticks are fully visible, data outside are truncated
scales: {
x: {
bounds: 'ticks', //here is the answer
type: 'time',
time: {
unit: 'day',
parser: 'DD-MMMM-YYYY',
tooltipFormat: 'DD-MMMM-YYYY'
},
grid: {
display: false
},
ticks: {
color: 'black',
align: 'center'
}
}
}
Source:stackexchange.com