Chartjs-How to replace the data array of my ChartJS

0👍

Inside function updateData, you need to access the data with chartData.datasets[0].data. Further you should update data with an array of number instead of string. Use Number to convert string to number as follows:

chartData.datasets[0].data = testArray.map(function (item) {
    return Number(item.production);
});

this can also be written in a simpler way:

chartData.datasets[0].data = testArray.map(item => Number(item.production));

Also instead of graphique.destroy() and graphInit() you can simply use graphique.update(). Maybe this answer is of some further help too: https://stackoverflow.com/a/60091960/2358409.

Leave a comment