Concerning this jsfiddle which uses chartjs v3.9.1 and the date-fns adapter:
https://jsfiddle.net/0a6c1ty5/22/
-
I’m trying to format the tick labels in the function
tick_label
but I’m only getting a string as input. Is there a way to get the full Date object so I can include the month and day-of-month in the tick label if I want? -
Is there a way to specify which times to use for tick lines along the time axis?
Here is the code from the fiddle:
var chart1
function tick_label(xvalue) {
console.log("xvalue:", xvalue, "type:", typeof(xvalue))
return xvalue
}
function doit() {
let t0 = 1742662800*1000; // Sat Mar 22 12:00:00 CDT 2025
let N = 31
data = [...Array(N)].map((a,i) =>
({ 'x': new Date(i*3600000+t0),
'y': ~~(Math.random()*40)
}))
config = {
type: "scatter",
data: { datasets: [{ label: "Random Values", data: data }] },
options: {
scales: {
x: { type: 'time', ticks: { callback: tick_label, color: 'red' } }
}
}
}
chart1 = new Chart(document.getElementById('chart1'), config);
}
doit()