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

前端 未结 12 1557
名媛妹妹
名媛妹妹 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:49

    I got the same problem, I have removed the canvas element and recreated canvas element and then again rendered with some delay.

    var element = document.getElementById("canvasId");
    
    element.parentNode.removeChild(element);
    
    var canv =  document.createElement("canvas");
    
    canv.setAttribute("id","canvasId");
    
    canv.style.height = "20vw"; // give height and width as per the requirement
    
    canv.style.width = "20vw"; 
    
    setTimeout(()=>{
     var grapharea = document.getElementById("canvasId").getContext("2d");
    },500)
    

提交回复
热议问题