HTML5 Canvas - Different Strokes

前端 未结 2 1958
囚心锁ツ
囚心锁ツ 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:53

    Add a ctx.beginPath() call before every line, and also a ctx.closePath() after every ctx.stroke()

    If you don't, every time you call the stroke() method, not only the new line will be drawn but also all the previous lines will be drawn again (with the new strokeStyle), since it's the same line path that is still open.

提交回复
热议问题