HTML5 Canvas - Different Strokes

前端 未结 2 1954
囚心锁ツ
囚心锁ツ 2020-12-20 16:35

I have to draw a graph with 3 different lines. A line graph.

I tried doing this:

function draw() 
{  
    var canvas = document.getElementById(\"canv         


        
2条回答
  •  暖寄归人
    2020-12-20 16:59

    Although there is a functional answer here, I'd just like to add this.

    var ctx1 = canvas.getContext("2d");
    var ctx2 = canvas.getContext("2d");
    var ctx3 = canvas.getContext("2d");
    

    They all refer to the same object. It does not create a new context, it uses the one that's already attached to the canvas element. Delta is totally right in saying that it strokes yellow over the entire path because you did not begin a new path. ctx.beginPath() will solve your troubles.

提交回复
热议问题