function draw() {
const labels = [
'January',
'February',
'March',
'April',
'May',
'June',
];
const data = {
labels: labels,
datasets: [{
label: 'test',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45],
}]
};
const config = {
type: 'doughnut',
data: data,
options: {}
};
const myChart = new Chart(
document.getElementById('myChart'),
config
);
}
This is my code and i keep getting this error message:
"Uncaught Error: Canvas is already in use. Chart with ID '0' must be destroyed before the canvas with ID 'myChart' can be reused."
Apart from this error code, my chart is able to display perfectly with no problems.
.destroy(). You must call it on the previously created chart object. You may also use the same variable for both charts. So before creating new chart you should destroy the canvas. Maybe calling this before making new chart will do the workmyChart.destroy()myChart.destroy()before making new chart it displays another error message that states "Cannot access 'myChart' before initialization". But if i were to addmyChart.destroy()at the end after i initialized 'myChart', my chart is gone and there isn't any error code for it.