2๐
โ
You indeed need to destroy the previous chart. Perhaps try with the following :
function plotChart() {
// removed code to retrieve data from firebase
var ctx = document.getElementById('donutChart').getContext("2d");
var data = {};
var opt = {
type: "doughnut",
data: data,
options: options
};
if (chart) chart.chart.destroy();
window.chart = new Chart(ctx, opt);
for (var i = 0; i < labelData.length; i++) {
chart.config.data.labels.push(labelData[i]);
}
chart.update();
}
1๐
It seems that your chart variable is being redeclared everytime the function is called and hence will never exist when you call plotchart(). Would recommend that you declare the variable before and bring it into the correct scope if it exists. That seems to be the core of your problem
Source:stackexchange.com