Chart.js canvas resize

前端 未结 13 1105
北海茫月
北海茫月 2020-11-30 23:39

In (Android WebView HTML5 canvas error) i posted a question regarding plotting graphs using Graph.js library. The problem i have now is that if i call the function to plot t

相关标签:
13条回答
  • As jcmiller11 suggested, setting the width and height helps. A slightly nicer solution is to retrieve the width and height of the canvas before drawing the chart. Then using those numbers for setting the chart on each subsequent re-draw of the chart. This makes sure there are no constants in the javascript code.

    ctx.canvas.originalwidth = ctx.canvas.width;
    ctx.canvas.originalheight = ctx.canvas.height;
    
    function drawchart() {
        ctx.canvas.width = ctx.canvas.originalwidth;
        ctx.canvas.height = ctx.canvas.originalheight;
    
        var chartctx = new Chart(ctx);
        myNewBarChart = chartctx.Bar(data, chartSettings); 
    }
    
    0 讨论(0)
提交回复
热议问题