Chartjs-How can i make a destroy button for my chart in JavaScript? (Chart.js)

0👍

your const myChart declaration is inside generateGraph function, only the code inside generateGraph has access to const myChart

what you could do is to use window.myChart instead of const myChart so that the variable is globally available and you clearCanvas() function can access it also using window.myChart.destroy()

Leave a comment