I am using a chart.js 3.x
JavaScript library for displaying charts.
I need to update the chart for which rendering is in progress.
I am using JavaScript Worker for updating the chart data.
for (var index=0;index < myjson.length;index++) {
chart.data.datasets[index].data.push(myjson[index]);
}
chart.update();
I am doing something like below to clean the chart dataset.
// Set the empty data and render the chart to clear the data
for (var index=0;index < chart.data.datasets.length;index++) {
chart.data.datasets[index].data = [];
}
chart.update();
But I see a few of the lines are still on the chart and not cleared properly.
May be continuous drawing is causing this issue.
I have also tried to clear()
and reset()
the chart but no effect.
So how to clear the chart data properly and redraw new dataset.