0👍
The code that you show us seems right, the only thing that you need is to shift the data in the dataset before adding the new value, like:
socket.on('temp', function(data) {
console.log(data.temp);
document.getElementById('date').innerHTML = data.date;
chart.data.datasets.forEach((dataset) => {
dataset.data.shift();
dataset.data.push(data.temp);
});
chart.update();
});
- Chartjs-I can't change the color of the grids in Chart.js
- Chartjs-Why chart renders after second click – react-chartjs-2
Source:stackexchange.com