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

你可能感兴趣的:(chartjs)