I'm using this tutorial to draw charts using chart.js in Wix Valo

For create the chart I'm using

async function chart(data_chart){

var chart = new ChartJSAPI($w('#customElement1'));

chart.customization = data_chart.customization

chart.data = data_chart.data 
}

And it working well

But when I call again to chart function

I got this error

chart.js:5552 Uncaught Error: Canvas is already in use. Chart with ID '0' must be destroyed before the canvas with ID 'myChart' can be reused. 

I tried to implement this:

Canvas is already in use. Chart with ID '0' must be destroyed before the canvas can be reused. chart.JS

But there is no function

chart.destroy();

How to destroy it?

1

There are 1 best solutions below

2
LeeLenalee On

After you have created the chart you don't have to re-create it. You can just update the data of the chart by setting chart.data = newData and chart.customization = newCustomization and then it should update automatically.