微信小程序中使用ECharts 异步加载数据实现图表功能
2019/6/27 7:50:33
本文主要是介绍微信小程序中使用ECharts 异步加载数据实现图表功能,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
具体代码如下所示:
<view class="container"> <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas> </view>
import * as echarts from '../../ec-canvas/echarts'; var barec = null Page({ onShareAppMessage: function (res) { return { title: 'ECharts 可以在微信小程序中使用啦!', path: '/pages/index/index', success: function () { }, fail: function () { } } }, data: { ec: { onInit: function (canvas, width, height) { barec = echarts.init(canvas, null, { width: width, height: height }); canvas.setChart(barec); return barec; } } }, onReady() { setTimeout(this.getData, 500); }, //getData方法里发送ajax getData(){ wx.showLoading({ title: '加载中...', }) wx.request({ url: 'http://192.168.3.81/heart.php', herder:{ "content-type":"json" }, success:function(res){ console.log(res); var data = res.data.info; console.log(data); barec.setOption({ grid: { left: '3%', right: '7%', bottom: '3%', containLabel: true }, tooltip: { // trigger: 'axis', showDelay: 0, formatter: function (params) { if (params.value.length > 1) { return params.seriesName + ' :<br/>' + params.value[0] + 'm ' + params.value[1] + 'm '; } else { return params.seriesName + ' :<br/>' + params.name + ' : ' + params.value + 'm '; } }, axisPointer: { show: true, type: 'cross', lineStyle: { type: 'dashed', width: 1 } } }, legend: { data: ["学生"], left: 'center' }, xAxis: [ { type: 'value', scale: true, axisLabel: { formatter: '{value} m' }, splitLine: { show: false } } ], yAxis: [ { type: 'value', scale: true, axisLabel: { formatter: '{value} m' }, splitLine: { show: false } } ], series: [{ name: '学生', // symbolSize: 20, data:data, type: 'scatter', markArea: { silent: true, itemStyle: { normal: { color: 'transparent', borderWidth: 1, borderType: 'dashed' } }, data: [[{ name: '教室', xAxis: '0', yAxis: '0' }, { xAxis: '20', yAxis: '20' }]] }, markPoint: { // data: [ // { type: 'max', name: '最大值' }, // { type: 'min', name: '最小值' } // ] }, markLine: { lineStyle: { normal: { type: 'solid' } }, // data: [ // { type: 'average', name: '平均值' }, // { xAxis: 160 } // ] } }] }) wx.hideLoading(); }, fail: function (res) { }, complete: function (res) { }, }) } });
总结
以上所述是小编给大家介绍的微信小程序中使用ECharts 异步加载数据实现图表功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对找一找教程网网站的支持!
这篇关于微信小程序中使用ECharts 异步加载数据实现图表功能的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28基于Python+Vue开发的口腔牙科预约管理系统
- 2024-09-28基于Python+Vue开发的酒店客房预订管理系统
- 2024-09-27使用js将ETH账户的资产打散其他账户web3
- 2024-09-27我轻松地将我的 React.js 应用程序翻译成了多种语言。下面是我是如何做到的... ??
- 2024-09-27?? 使用 useMemo 和 useCallback 加速 React:告别缓慢的重新渲染!??
- 2024-09-27Vue CLI多环境配置教程:新手入门指南
- 2024-09-27Vue CLI多环境配置教程:快速入门指南
- 2024-09-27Vue CLI教程:新手入门指南
- 2024-09-27Vue CLI教程:初学者快速入门指南
- 2024-09-27Vue3公共组件教程:入门与实践