作者在初始版本中,对ecomfe/echarts-for-weixin做了少量改动来兼容uni-app 需要通过uni-app编译后使用。
https://ext.dcloud.net.cn/plugin?id=3464#detail
使用过程中发现无法获取到formatter,比较简单的办法就是手动添加,也就是在setOption之前先加上formatter方法。
找到uni-ec-canvas文件夹下uni-ec-canvas.vue,在this.$curChart.setOption(this.ec.option);之前,手动添加formatter,示例如下
initChart(canvas, width, height, canvasDpr) {
this.$curChart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: canvasDpr,
});
canvas.setChart(this.$curChart);
this.ec.option.series[0].detail.formatter = function formatter(value) {
return "{value|" + value.toFixed(1) + "}{unit|%}";
};
this.ec.option.series[0].axisLabel.formatter = function formatter(value) {
if (value === 0) {
return "0";
} else if (value === 100) {
return "100";
}
return "";
};
this.$curChart.setOption(this.ec.option);
this.$emit("inited", this.$curChart);
return this.$curChart;
},
第8行与第11行。
没添加前:
添加后:
可自行打印this.ec.option观察。