微信小程序使用ec-canvas实现echart折线图时报错处理方法

控制台报错: 不支持颜色:none

 

解决办法:参考 https://developers.weixin.qq.com/community/enterprisewechat/doc/0000c66e358490a3e89c7a7fc56400 下的回答

 

在 echarts 的 ec-canvas 目录下应该有一个 wx-canvas.js 文件,这个文件里应该提供了一个类,里面在初始化化会执行一个 _initStyle 方法,可以在这个方法中加入下面这段代码:

var styles = [

      "fillStyle",

      "strokeStyle",

      "globalAlpha",

      "textAlign",

      "textBaseAlign",

      "shadow",

      "lineWidth",

      "lineCap",

      "lineJoin",

      "lineDash",

      "miterLimit",

      "fontSize",

    ];

 

    styles.forEach((style) => {

      Object.defineProperty(ctx, style, {

        set: (value) => {

          if (

            (style !== "fillStyle" && style !== "strokeStyle") ||

            (value !== "none" && value !== null)

          ) {

            ctx["set" + style.charAt(0).toUpperCase() + style.slice(1)](value);

          }

        },

      });

    });

已解决

 

posted @ 2022-01-20 11:07  深如墨&淡如水  阅读(847)  评论(0编辑  收藏  举报