There are multiple Chart.js charts that may need to be updated at a later time.
Is it feasible to retrieve the myChart object from the canvas element when needing to update the chart, or is it necessary to preserve each myChart object in the global scope?
for(var i=1; i<=5; i++) {
createChart(i);
}
function createChart(i) {
var $chart = $('<canvas id="chart-' + i + '" width="400" height="400"></canvas>').appendTo('body');
var myChart = new Chart($chart, {
data: {
datasets: [{
data: [Math.random(), Math.random(), Math.random(), Math.random()]
}]
}
});
}
Below is some pseudo-code on how I would like to update, for example, chart 2 at a later time:
var updateChart = $('#chart-2'); // This is where I'd need to extract the chart data from the canvas element
updateChart.data.datasets[0].data = updateChart.data.datasets[0].data.push(Math.random());
updateChart.update();