麻烦参考echarts官方文档,重新修改一下代码
时间: 2023-10-26 11:44:23 浏览: 85
非常抱歉,我之前的代码并没有参考官方文档。以下是参考官方文档后,重新修改的代码示例:
首先,创建一个名为`echarts-pie`的自定义组件,创建一个`echarts-pie.wxml`文件,内容如下:
```html
<view class="echarts-pie">
<ec-canvas id="mychart-dom" canvas-id="mychart" ec="{{ ec }}"></ec-canvas>
</view>
```
然后,在同一目录下创建`echarts-pie.js`文件,内容如下:
```javascript
import * as echarts from '../../ec-canvas/echarts';
Component({
properties: {
ec: {
type: Object,
value: {},
observer: function(newVal, oldVal) {
if (newVal && newVal.series && newVal.series.length > 0) {
this.initChart();
}
}
}
},
lifetimes: {
attached: function() {
this.initChart();
}
},
methods: {
initChart: function() {
const that = this;
this.selectComponent('#mychart-dom').init((canvas, width, height) => {
const chart = echarts.init(canvas, null, {
width: width,
height: height
});
canvas.setChart(chart);
chart.setOption(that.data.ec);
return chart;
});
}
}
});
```
接下来,在页面中引用该组件,在页面的`.json`文件中添加以下代码:
```json
{
"usingComponents": {
"ec-canvas": "../../components/ec-canvas/ec-canvas",
"echarts-pie": "../../components/ech
阅读全文