2👍
ChartJS API actually offers the getChart
method to do what you want:
let chart = Chart.getChart('chart-2'); // Select by canvas ID
// OR
let canvas = document.querySelector('#chart-2')
let chart = Chart.getChart(canvas); // Select using the canvas element
// You can now update your chart
chart.data.datasets[0].data = newData;
chart.data.labels = newLabels;
chart.update();
- [Chartjs]-Chartjs – show elements in all datasets on hover using bar chart
- [Chartjs]-ChartJS Line Charts – remove color underneath lines
1👍
Chart.helpers.each(Chart.instances, function(instance){
console.log(instance);
});
0👍
I would recommend to store all data sent to chart in arrays. Once the array is updated you can send:
HTTP/AJAX/SOCKET.IO
indication to the client, and update the chart.
Source:stackexchange.com