I am using the Chart.js library to draw a bar graph, it is working fine, but now I want to destroy the bar graph and make
In order to solve this problem I have used jQuery's add()
and remove()
methods, to clear the canvas. I am removing the component and before drawing it again I am appending the canvas again with the same id using jQuery's append()
method.
redraw(){
$("#myChart").remove();// removing previous canvas element
//change the data values or add new values for new graph
$("#chart_box").after("");
// again adding a new canvas element with same id
generateGraph();// calling the main graph generating function
}