Destroy chart.js bar graph to redraw other graph in same

前端 未结 12 1533
名媛妹妹
名媛妹妹 2020-11-30 06:41

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

12条回答
  •  既然无缘
    2020-11-30 06:52

    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 
    
    }
    

提交回复
热议问题