[Chartjs]-Chart.js: get chart data from canvas

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();

1👍

Chart.helpers.each(Chart.instances, function(instance){
    console.log(instance);
});

Update:
https://jsfiddle.net/furd1L27/14/

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.

Leave a comment