Number2 echarts动态获取数据
继续上一篇,结合echarts动态获取数据
官方提供了一个微信与echarts相结合的数据,里面就是简单的各种工具,数据获取没有进行动态绑定,各种搜索资料最后编写了一个动态获取数据的方法
这里以官方示例pie做改造
1.index.js
import * as echarts from '../../ec-canvas/echarts';
const app = getApp();
function setOption(chart,piedata){
var option = {
backgroundColor: "#ffffff",
series: [{
label: {
normal: {
fontSize: 14
}
},
type: 'pie',
center: ['50%', '50%'],
radius: ['20%', '40%'],
data: piedata
}]
};
chart.setOption(option);
return chart;
}
Page({
data: {
ec: {
//onInit: initChart
// 将 lazyLoad 设为 true 后,需要手动初始化图表
lazyLoad: true
}
},
initpie:function(piedata){
let ecComponent = this.selectComponent('#mychart-dom-pie');
ecComponent.init((c