1👍
Your code works just fine with the initial data you provided. I only corrected the xAxes.time
definition but even without this change, it works.
Maybe you’re using an outdated version of Chart.js v2 or you don’t use the bundled version of Chart.js that includes Moment.js (required for the time axis) in a single file.
Please take a look at your runnable code below:
const chartJS = new Chart('canvas', {
type: 'line',
data: {
datasets: [{
data: [],
fill: false,
borderColor: 'rgb(75, 192, 192)',
stepped: false,
}]
},
options: {
title: {
display: true,
text: "Chart.js Time Scale"
},
scales: {
xAxes: [{
type: "time",
time: {
unit: 'day',
tooltipFormat: 'll'
},
scaleLabel: {
display: true,
labelString: 'Date'
}
}]
}
}
});
let serie = [{"x": 1594887960*1000, "y": 95.95},{"x": 1596488640*1000,"y": 42.95}];
chartJS.data.datasets[0].data = serie;
chartJS.update();
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.bundle.min.js"></script>
<canvas id="canvas"></canvas>
- Chartjs-How to set Chart.js axis minumum to 0?
- Chartjs-Why are some react-chartjs-2 options being ignored?
Source:stackexchange.com