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