Chartjs-Destroy method implementation in pie chart chartjs

0๐Ÿ‘

I found my answer by this way.
Thanks!

       var ctx = document.getElementById("chart-area").getContext("2d");
               if(myPie!=null){
    myPie.destroy();
}
    myPie = new Chart(ctx, config);

0๐Ÿ‘

To destroy chart, you need to call โ€œdestroyโ€ method on variable, which contains an instance of the chart.
Simple example for your case:

var ctx = document.getElementById("chart-area").getContext("2d");
var myPie = new Chart(ctx, config);

...some additional code...

// Destroy myPie instance
myPie.destroy();

Leave a comment