1👍
There is a chart helper API which stores all the instances of a chart for a particular page. You can make use of that to find out if there is nothing present then create logic else update logic.
See the sample below. This is not the most refined logic but just to give an idea.
var chartUpdated = false;
Chart.helpers.each(Chart.instances, function(instance) {
if (instance.chart.canvas.id === "yourCanvasId") {
//perform the update logic
chartUpdated = true;
return;
}
});
if(!chartUpdated)
{
//perform the create logic
}
- Chartjs-How do I run Chart.js with Angular 10 SSR / universal?
- Chartjs-Uncaught ReferenceError: Chart is not defined at test.html:11
Source:stackexchange.com