The dates in the x axis are showing times and time zones. I just want to show month and day.
<code>function dateSeries(startDate, endDate) {
let dates = [];
let currentDate = new Date(startDate);
while (currentDate <= endDate) {
dates.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
return dates;
};
let ctx = document.getElementById('myChart');
let goal = [5,4,3,2,1,0];
let dates = dateSeries(new Date('2024-12-03'), new Date('2024-12-08'));
let myChart = new Chart(ctx, {
type: 'line',
data: {
labels: dates,
datasets: [
{
label: 'Goal',
data: goal,
borderColor: 'rgba(142, 180, 227, 1)',
}
]
},
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'MMM DD'
}
}
}
}
}
});
</code>
<code>function dateSeries(startDate, endDate) {
let dates = [];
let currentDate = new Date(startDate);
while (currentDate <= endDate) {
dates.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
return dates;
};
let ctx = document.getElementById('myChart');
let goal = [5,4,3,2,1,0];
let dates = dateSeries(new Date('2024-12-03'), new Date('2024-12-08'));
let myChart = new Chart(ctx, {
type: 'line',
data: {
labels: dates,
datasets: [
{
label: 'Goal',
data: goal,
borderColor: 'rgba(142, 180, 227, 1)',
}
]
},
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'MMM DD'
}
}
}
}
}
});
</code>
function dateSeries(startDate, endDate) {
let dates = [];
let currentDate = new Date(startDate);
while (currentDate <= endDate) {
dates.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
return dates;
};
let ctx = document.getElementById('myChart');
let goal = [5,4,3,2,1,0];
let dates = dateSeries(new Date('2024-12-03'), new Date('2024-12-08'));
let myChart = new Chart(ctx, {
type: 'line',
data: {
labels: dates,
datasets: [
{
label: 'Goal',
data: goal,
borderColor: 'rgba(142, 180, 227, 1)',
}
]
},
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'MMM DD'
}
}
}
}
}
});
It renders as:
I feel like my “options” code looks like all the examples I found, but I can’t get the axis to format properly.
1