chartjs的canvas清空重繪
阿新 • • 發佈:2019-02-13
jquery操作canvas失敗
chartjs連續重新繪製同一個canvas會出現重疊
解決方案:
chartDivId 未canvas 的id
if(!!(document.getElementById(chartDivId))){ document.getElementById(chartDivId).remove(); } var cdom = document.createElement("canvas"); cdom.setAttribute("id",chartDivId); cdom.setAttribute("height","86"); cdom.style.setProperty("padding","30px") document.getElementById(chartDivId+"_p").appendChild(cdom); var canvas = document.getElementById(chartDivId); var ctx = canvas.getContext("2d"); //ctx.clearRect(0,0,canvas.width,canvas.height); var chart = new Chart(ctx, {type: 'line', data: lineData, options:lineOptions});