微信小程序控制台报echarts颜色识别报错 非法颜色: none 报错

审核中 echarts.js 未结 已结 置顶 精帖
删除 置顶 取消置顶 加精 取消加精
66 0
yswl
yswl VIP3 2022-05-31 14:20:43
悬赏:60金币 编辑此贴

image


在 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);
          }
        },
      });
    });