0👍
The time
axis type in ChartJS supports min
and max
– so you can work out what the oldest value you want displayed it and set its x
value as min
.
let data = [/* some data */]
data.sort((a, b) => a.x < b.x)
const min = data.length > 100 ? data[99].x : data[data.length - 1].x
var chart = new Chart(ctx, {
type: 'line',
data,
options: {
scales: {
xAxes: [{
time: {
min
}
}]
}
}
})
Source:stackexchange.com