Zhuyi731 / echarts-for-wx-uniapp

uni-app echarts vue2小程序专用
331 stars 37 forks source link

formatter 不能定义成函数? #32

Closed luzhaopan closed 3 years ago

luzhaopan commented 3 years ago

yAxis: { type: 'value', axisLabel: { color: '#999', textStyle: { fontSize: 10 }, formatter: (value, index) => { return value + 'kg'; } }, }, formatter中的function不起作用

Zhuyi731 commented 3 years ago

yAxis: { type: 'value', axisLabel: { color: '#999', textStyle: { fontSize: 10 }, formatter: (value, index) => { return value + 'kg'; } }, }, formatter中的function不起作用

vue的data里不能放函数,会被序列化。只能手动setOptions 需要通过获取实例$curChart后。通过this.$curChart.setOption来设置echart配置

luzhaopan commented 3 years ago

console.log(this.$refs['uni-ec-canvas'].$curChart.setOption())

vendor.js?t=wechat&s=1623979961505&v=67c7528469866a1a92210909eecde7b3:3982 [Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'setOption' of undefined"

found in

---> at pages/wealth-report/component/strategy-charts.vue pages/wealth-report/index.vue(env: Windows,mp,1.05.2105170; lib: 2.16.1)

试了好多种,加了延迟也不行,setOption找不到,一直报的undefined

通过以下的方式可以了 mounted() { this.$refs['uni-ec-canvas'].ec.option = this.getOption() this.$refs['uni-ec-canvas'].init() },