1. 程式人生 > >chartjs的canvas清空重繪

chartjs的canvas清空重繪

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});