微信小程序 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
  },
相关推荐
Jiaberrr5 小时前
前端实战:使用JS和Canvas实现运算图形验证码(uniapp、微信小程序同样可用)
前端·javascript·vue.js·微信小程序·uni-app
h177113472056 小时前
单身狗的逆袭之路之开发相亲交友系统
微信小程序·小程序·交友·系统开发·回归算法
李宥小哥8 小时前
微信小程序05-常用API下
微信小程序·小程序
李宥小哥8 小时前
微信小程序06-综合项目点餐系统
微信小程序·小程序·notepad++
包淼淼15 小时前
微信小程序自定义navigationBar顶部导航栏(背景图片)适配所有机型,使用tdesign-miniprogram t-navbar设置背景图片
微信小程序·小程序·tdesign
2401_8441379515 小时前
JAVA同城生活新引擎外卖跑腿团购到店服务多合一高效系统小程序源码
微信·微信小程序·小程序·生活·微信公众平台·微信开放平台
骆晨学长16 小时前
基于springboot的智慧社区微信小程序
java·数据库·spring boot·后端·微信小程序·小程序
李宥小哥20 小时前
微信小程序07-开发进阶
微信小程序·小程序·notepad++
2401_845937531 天前
PHP一键约课高效健身智能健身管理系统小程序源码
微信·微信小程序·小程序·微信公众平台·微信开放平台
程序员入门进阶1 天前
基于微信小程序的科创微应用平台设计与实现+ssm(lw+演示+源码+运行)
微信小程序·小程序