2👍
✅
As long as you are using new Chart()
constructor, accoding to the documentation destroy
method should be called before the canvas is reused for a new chart.
In your case it should work as follows
if(window[configs.selectorId] && window[configs.selectorId] !== null){
if (typeof window[configs.selectorId].destroy === 'function') {
window[configs.selectorId].destroy();
}
delete window[configs.selectorId];
}
Here is a snippet I’ve created on the basis of your code:
https://codepen.io/sergey_mell/pen/qBdBVpe
I’ve just changed your random data API to locally random generated data
Please, let me know if my answer is not clear enough or you need some additional information
Source:stackexchange.com