3👍
✅
You’re doing everything right, and you’re so close. I believe there’s no need to store anything in this.chart. Simply return and render. To fix your multi-instance error, simply add a check for chart existence before rendering.
divClick()
{
var chartExist = Chart.getChart("myChart"); // <canvas> id
if (chartExist != undefined)
chartExist.destroy();
$('#myModal').modal('show');
this.getChartData()
}
getChartData(): any {
return new Chart(this.canvas.nativeElement.getContext('2d'), {data})
}
In your HTML, simply add id for chart
<canvas id="myChart" #chart>{{ chart }}</canvas>
Source:stackexchange.com