Canvas绘制线条
发布于 5 年前 作者 ping05 12007 次浏览 来自 问答

如下代码,使用canvas绘制两个数组,前一数组e使用setStrokeStyle = #000000

,即黑色;后一数组使用绿色,但是绘制出来两条线都变成了绿色,求解,我错在哪儿呢?

//绘制e
      var ys = es;
      var i = 0;
      context.setStrokeStyle("#000000")
      context.moveTo(0, ys[0]);
      for(i = 0; i < ys.length;i++){
        if(ys[i] == ""){
            ys[i] = 0;
        }
        if(i != 0){
          context.lineTo(i * 8, ys[i]);
        }
      }
      context.stroke()
      //绘制u
      var ys = us;
      var i = 0;
      context.setStrokeStyle("#1B9022");
      context.setLineWidth(2);
      context.moveTo(0, ys[0]);
      for(i = 0; i < ys.length;i++){
        if(ys[i] == ""){
            ys[i] = 0;
        }
        if(i != 0){
          context.lineTo(i * 8, ys[i]);
        }
      }
      context.stroke()
      wx.drawCanvas({
        canvasId: 'firstCanvas',
        actions: context.getActions()
      })
2 回复

有人在吗?

回到顶部