小程序-图表

如i果要封装图表组件,可以基于这个案例,每次传入的是一个对象即可。

 import * as echarts from '../echarts';

this
.ecComponent = this.selectComponent('#chart'); this.ecComponent.init((canvas, width, height, dpr) => { const chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr // new }); chart.setOption(c_option);

this.chart = chart; this.setData({ isLoaded: true, }); // 注意这里一定要返回 chart 实例,否则会影响事件处理等 return chart; });

 

其中,下载图表定制化的 线和壮壮图js,本地运行报错。

// 下载好替换之后,提示什么TypeError: t.domTarget.addEventListener is not a functionfunction Ii(t, e, n, i) {
  t.mounted[e] = n, t.listenerOpts[e] = i, t.domTarget.addEventListener(e, n, i)
}
// 直接改成
function Ii(t, e, n, i) {
  t.mounted[e] = n, t.listenerOpts[e] = i, 1
}
// 也就是删掉 ,
t.domTarget.addEventListener(e, n, i)

 

https://github.com/ecomfe/echarts-for-weixin/blob/82e6cdfe5347265c04cced222bd6398dcb6eb279/pages/lazyLoad/index.js#L10

posted @ 2025-12-03 15:29  微宇宙  阅读(4)  评论(0)    收藏  举报