I am using a function to create a chart which uses chart.js. Unfortunately, whenever I am trying to call chart.destroy() I get the error:
"chart.destroy() is not a function". My code looks as following:
var chart = {};
createChart(x_axis_data, y_axis_data, chart); //Function creating chart
The chart itself is created inside the function with following:
chart = new Chart(document.getElementById(id),{....
The chart is created successfully. However, I cannot delte the chart by calling: chart.destroy. I have already tried to use
window.chart.destroy()
without any success.
Set window.chart =
rather than relying on the implicit function of chart =
. If you were using strict mode with your code, it should throw a warning.