[Chartjs]-Chart.js + Angular 5 – Destroy() multiple dynamic charts created through *ngFor loop

1👍

Solved myself by creating charts directly into charts array.

 var ctx4: any = document.getElementById(`chart` + i);
    this.charts.push(new Chart(ctx4, bar)); 

and destroyed the charts by iterating on charts array.

if (this.charts) {
      this.charts.forEach(p => {
        p.destroy();
      });
    }

Leave a comment