Charts .js update when array changes

👍:0

From the documentation:

.update( )

Calling update() on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those ione n imatanred eendr loop.

myLineChart.datasets[0].points[2].value = 50;
// Would update the first dataset's value of 'March' to be 50
myLineChart.update();
// Calling update now animates the position of March from 90 to 50.

I got it working with the following code, let me know if there’s a more efficient way to do it!

window.myLine.datasets[0].points[0].value = hmcArray[0];
window.myLine.datasets[0].points[1].value = hmcArray[1];
window.myLine.datasets[0].points[2].value = hmcArray[2];
window.myLine.datasets[0].points[3].value = hmcArray[3];
window.myLine.datasets[0].points[4].value = hmcArray[4];
window.myLine.datasets[0].points[5].value = hmcArray[5];
window.myLine.datasets[0].points[6].value = hmcArray[6];
window.myLine.datasets[0].points[7].value = hmcArray[7];
window.myLine.datasets[0].points[8].value = hmcArray[8];
window.myLine.datasets[0].points[9].value = hmcArray[9];
window.myLine.update();

Leave a comment