把下面代码的数据换成后台接口的动态数据给出修改后的代码import as echarts from componentsec-canvasechartsfunction initChartcanvas width height dpr const chart = echartsinitcanvas null width width height height device
import * as echarts from '../../components/ec-canvas/echarts'
function initChart(canvas, width, height, dpr) { const chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr }); canvas.setChart(chart);
wx.request({ url: '后台接口的URL', method: 'GET', success: function(res) { var data = res.data; // 后台返回的动态数据
var option = {
backgroundColor: "#ffffff",
series: [{
label: {
normal: {
fontSize: 14
}
},
type: 'pie',
center: ['50%', '50%'],
radius: ['20%', '40%'],
data: data // 使用后台返回的数据
}]
};
chart.setOption(option);
}
});
return chart; }
Page({ data: { ec: { onInit: initChart } } }
原文地址: https://www.cveoy.top/t/topic/ixYO 著作权归作者所有。请勿转载和采集!