I'm trying to display a time linear graph in Angular 14 with chart.js
version 3.9.1
.
I've been trying a lot of examples from https://www.chartjs.org/docs/latest/ or youtube tutorials and I couldn't find something to work. Below you can see what I wanted to achieve and the code that is not working. Any help or idea will be very helpful.
The yAxis is number
and xAxis is DateTime
.
TS file
data: ChartData = {
labels: [new Date('2021-11-16T00:00:00'), new Date('2021-12-16T00:00:00'), new Date('2022-01-16T00:00:00')],
datasets: [{
type: 'line',
data: [2, 3, 1],
label: 'Title',
fill: true,
}],
};
options: ChartOptions = {
plugins: {
title: {
text: 'Chart.js Time Scale',
display: true
}
},
scales: {
x: {
type: 'time',
time: {
tooltipFormat: 'DD T'
},
title: {
display: true,
text: 'Date'
}
},
y: {
title: {
display: true,
text: 'value'
}
}
},
};
HTML file
<canvas baseChart style="height: 20em;"
type="line"
[data]="data"
[options]="options">
</canvas>
Expected behavior: to see something like this
Actual behavior: displays nothing