Encountering the error message "Canvas is already in use. Chart with ID ' ' must be destroyed before the canvas with ID 'MyChart' can be reused." pops up 4/5 times for each specific id in the console. Interestingly, when staying on the page and adding data, the error doesn't show up. However, if navigating to another page and returning to this component to add data, the error reappears.
if (this.chart){
this.chart.destroy();
}
this.chart = new Chart('MyChart', {
type: 'line',
data: {
labels: monthLabels,
datasets: [
{
label: 'Weight',
data: weightLabels,
backgroundColor: 'blue',
},
],
},
options: {
aspectRatio: 2.5,
},
});