微信小程序 echarts 画多个横向柱状图

然后是json

javascript 复制代码
{
  "usingComponents": {
    "ec-canvas": "../../common/ec-canvas/ec-canvas"
  },
  "navigationBarTitleText": "主题活动"
}

ec-canvas获取方式 在链接里下载代码 然后copy ec-canvas文件夹到自己的项目

https://gitcode.net/mirrors/ecomfe/echarts-for-weixin?utm_source=csdn_github_accelerator&from_codechina=yeshttps://gitcode.net/mirrors/ecomfe/echarts-for-weixin?utm_source=csdn_github_accelerator&from_codechina=yes

javascript 复制代码
//js里引入echarts 在page上面
import * as echarts from '../../common/ec-canvas/echarts'
Page({...})
  getStatisticThemeActivitiesTrend(){
    const that = this
    let oUserInfo = this.data.userInfo
    util.request(api.statisticThemeActivitiesTrend + oUserInfo.userId + '&startDate=' + that.data.startDate + '&endDate=' + that.data.endDate, '', 'get').then(res => {
      if (res.code == 200) {
        let odata = res.data
        this.setData({
          info: odata
        })

        if(!odata.themeList || odata.themeList.length == 0){
          util.alert("暂无数据")
          return
        }
        
        //主要代码
        odata.themeList.forEach(function (item, index) {        
          let echartsComponnet = that.selectComponent('#area-dom-'+index);
          echartsComponnet.init((canvas, width, height, dpr) => {
            // 初始化图表
            const Chart = echarts.init(canvas, null, {
              width: width,
              height: height,
              devicePixelRatio: dpr
            });
            Chart.setOption(that.getAreaPie(item));
            // 注意这里一定要返回 chart 实例,否则会影响事件处理等
            return Chart;
          });          
        })
      } else {
        wx.showModal({
          title: res.msg,
          icon: 'error',
          showCancel: false,
          duration: 3000
        });
      }
    });
  },

  getAreaPie(odata) {    
    let option = {
      grid: { //图表距边框的距离
        top: 0,
        right: 30,        
        bottom: 0,
        left: 0,
        containLabel: false,
      },
      xAxis: {
        type: 'value',
        "splitLine": {     //网格线
          "show": false
        }
      },
      yAxis: {
        show : false,
        type: 'category',
        data: ['','','','']
      },
      series: [
        {
          data: [
            odata.countActivityNumber, 
            odata.countPhysicalRecordNumber, 
            odata.countDetailNumber, 
            odata.countObservationNumber],
          type: 'bar',
          itemStyle: {   
            //通常情况下:
            normal:{  
              label : {
                show: true,
                position: 'right',
              },
         //每个柱子的颜色即为colorList数组里的每一项,如果柱子数目多于colorList的长度,则柱子颜色循环使用该数组
              color: function (params){
                var colorList = ['#70b603', '#00bfbf', '#027db4', '#6300bf']
                return colorList[params.dataIndex];
              }
            },
            //鼠标悬停时:
            emphasis: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            },
          },
        }
      ]
    };
    return option
  },
相关推荐
一铭1119911 小时前
微信小程序可视化搭建实战:模板、组件与发布验收
前端·低代码·微信小程序·小程序·页面设计·可视化搭建·发布验收
愚公搬代码14 小时前
【愚公系列】《微信小程序项目实战(AI编程+视频图解)》049-项目实战:使用 AI 编程工具辅助实现图书分类页面
人工智能·微信小程序·ai编程
千寻技术帮16 小时前
基于微信小程序的装修管理系统(源码+脚本+文档)50032
数据库·spring boot·微信小程序·毕业设计·装修管理
千寻技术帮16 小时前
医院挂号小程序(源码+脚本+文档)50031
mysql·微信小程序·小程序·毕业设计·医院管理·医院挂号
愚公搬代码18 小时前
【愚公系列】《微信小程序项目实战(AI编程+视频图解)》047-设备应用 API
微信小程序·音视频·ai编程
用户112936112191 天前
没写样式为什么还找我要 wxss?uni-app 这个 ENOENT 坑多数人误判了
前端·微信小程序·uni-app
源码手记1 天前
基于微信小程序的流浪动物救助与领养系统-毕设源码
微信小程序·小程序·课程设计
拖孩1 天前
群里有人开始比「次数」之后,我做了个排行榜小程序
前端·后端·微信小程序
源码手记2 天前
基于微信小程序的个性化音乐推荐系统-毕设源码
微信小程序·小程序·课程设计
千寻技术帮3 天前
基于微信小程序的家政服务系统(源码+脚本+文档)_50039
mysql·微信小程序·小程序·毕业设计·家政服务