微信小程序> 微信小程序显示折线图-小程序统计图插件-微信小程序统计图

微信小程序显示折线图-小程序统计图插件-微信小程序统计图

浏览量:4480 时间: 来源:程序猿_小天

插件地址:https://github.com/xiaolin3303/wx-charts/blob/master/dist/wxcharts.js

推荐使用百度的echarts来做图表!!!微信小程序折线图效果:然后在XXX.js中配置:

1.在顶部写入:

2.写一个独立的方法(或者直接写在onload里面):

我这里写的方法名是getMothElectro,我后面试在onload里面调用了的。

getMothElectro:function(){varwindowWidth=320;try{varres=wx.getSystemInfoSync();windowWidth=res.windowWidth;}catch(e){console.error('getSystemInfoSyncfailed!');}yuelineChart=newwxCharts({//当月用电折线图配置canvasId:'yueEle',type:'line',categories:['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'],//categoriesX轴animation:true,//background:'#f5f5f5',series:[{name:'总用电量',//data:yuesimulationData.data,data:[1,6,9,1,0,2,9,2,8,6,0,9,8,0,3,7,3,9,3,8,9,5,4,1,5,8,2,4,9,8,7],format:function(val,name){returnval.toFixed(2)+'kWh';}},{name:'电池供电量',data:[0,6,2,2,7,6,2,5,8,1,8,4,0,9,7,2,5,2,8,2,5,2,9,4,4,9,8,5,5,5,6],format:function(val,name){returnval.toFixed(2)+'kWh';}},{name:'光伏供电量',data:[6,4,9,7,1,4,5,1,1,8,8,6,6,2,2,2,0,5,5,8,8,8,8,9,0,4,6,9,2,1,6],format:function(val,name){returnval.toFixed(2)+'kWh';}},{name:'市电供电量',data:[0,4,3,3,1,7,7,7,9,9,3,3,0,0,5,6,0,4,1,2,0,1,3,9,2,5,1,8,3,4,2],format:function(val,name){returnval.toFixed(2)+'kWh';}}],xAxis:{disableGrid:true},yAxis:{title:'当月用电(kWh)',format:function(val){returnval.toFixed(2);},max:20,min:0},width:windowWidth,height:200,dataLabel:false,dataPointShape:true,extra:{lineStyle:'curve'}});}

3.然后在onload里面在调用一次:

4.在增加一个触摸显示功能:

yueTouchHandler:function(e){//当月用电触摸显示console.log(daylineChart.getCurrentDataIndex(e));yuelineChart.showToolTip(e,{//showToolTip图表中展示数据详细内容background:'#7cb5ec',format:function(item,category){returncategory+'日'+item.name+':'+item.data}});},

这样就OK了!

如果不懂,请联系我。

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎