微信小程序 Echarts 图表动态数据渲染 - 使用后台接口获取数据
import* as echarts from''../../components/ec-canvas/echarts''\nfunction initChart(canvas, width, height, dpr) {\n const chart = echarts.init(canvas, null, {\n width: width,\n height: height,\n devicePixelRatio: dpr\n });\n canvas.setChart(chart);\n\n wx.request({\n url: '后台接口的URL',\n method: 'GET',\n success: function(res) {\n var data = res.data; // 后台返回的动态数据\n\n var option = {\n backgroundColor: '#ffffff',\n series: [{\n label: {\n normal: {\n fontSize: 14\n }\n },\n type: 'pie',\n center: ['50%', '50%'],\n radius: ['20%', '40%'],\n data: data // 使用后台返回的数据\n }]\n };\n chart.setOption(option);\n }\n });\n\n return chart;\n}\nPage({\n data: {\n ec: {\n onInit: initChart\n }\n }\n})
原文地址: https://www.cveoy.top/t/topic/qffl 著作权归作者所有。请勿转载和采集!