关于Echarts饼图循环series里data

此处为效果图 根据接口返回的数据进行循环

第一步:先将需要循环的series置空 循环你想要的数组(ps:此处我的数组为ytgsList)

 var myChart4 = echarts.init(this.$refs.myChart4)
      var series=[]
      for (var i=0,len=this.ytgsList.length;i<len;i++){
        series.push({
         value:this.ytgsList[i].situationCount,
          name:`${this.ytgsList[i].situationCount}
${this.ytgsList[i].situationName}`
        })
      }

第二步:直接创建 此处color我使用的是渐变色 legend的设置是为了显示上面数据下面昵称的需求

title里是是在环形中央显示文字信息 series里的data直接用上面循环里做的就好了

   var option = {
        tooltip: {
          trigger: 'item'
        },
        legend:{
          orient: 'horizontal',//纵向排列
          align:'left',
          top:'20%',
          left:'70%',
          width:'130',
          itemWidth: 15,
          textStyle: {
            color: 'rgba(255,255,255,1)',
            width: 100,
            overflow: 'break',
          }
        },
        color: [
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
              offset: 0, color: 'rgba(205, 255, 32, 1)' // 0% 处的颜色
            }, {
              offset: 1, color: 'rgba(1, 16, 23, 1)' // 100% 处的颜色
            }],
            global: false // 缺省为 false
          },
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
              offset: 0, color: 'rgba(1, 101, 254, 1)' // 0% 处的颜色
            }, {
              offset: 1, color: 'rgba(1, 16, 23, 1)' // 100% 处的颜色
            }],
            global: false // 缺省为 false
          },
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
              offset: 0, color: 'rgba(255, 224, 46, 1)' // 0% 处的颜色
            }, {
              offset: 1, color: 'rgba(1, 16, 23, 1)' // 100% 处的颜色
            }],
            global: false // 缺省为 false
          },
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
              offset: 0, color: 'rgba(1, 195, 241, 1)' // 0% 处的颜色
            }, {
              offset: 1, color: 'rgba(1, 16, 23, 1)' // 100% 处的颜色
            }],
            global: false // 缺省为 false
          },
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
              offset: 0, color: 'rgba(46, 229, 165, 1)' // 0% 处的颜色
            }, {
              offset: 1, color: 'rgba(1, 16, 23, 1)' // 100% 处的颜色
            }],
            global: false // 缺省为 false
          },

        ],
        title: {
          left: '48.5%',
          top: 'center',
          text: `{topTitle|${this.ytgsListAllCount}}` + '\n' + '\n' + '业态总数',
          textAlign: 'center',
          textStyle: {
            //富文本标签自定义
            rich: {
              topTitle: {
                color: '#41C1FF',
                fontWeight: '600',
                fontSize: 12
              }
            },
            fontSize: 11,
            width: 100,
            color: 'rgba(255, 255, 255, 1)'
          }
        },
        series:[
          {
            name: '个数',
            type: 'pie',
            radius: ['45%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center',
            },
            labelLine: {
              show: false
            },
            data:series
          },
        ]
      };

第三步:创建并设置其自适应窗口大小

 myChart4.setOption(option);
      window.addEventListener("resize", () => {
        if (this.$refs.myChart4) myChart4.resize();
      });

整体如下

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
折线图的series循环出错可能有多种原因,根据提供的引用内容,我无法确定具体的错误原因。但是我可以给出一些常见的错误原因和解决方法。 1. 数据格式错误:在循环series时,确保数据格式正确。根据引用\[2\]中的代码,series数据应该是一个包含两个数组的对象,分别是money和context。请确保这两个数组的长度相等,并且每个元素的类型正确。 2. 数据源错误:检查数据源是否正确加载。根据引用\[3\]中的代码,可能需要通过调用billService.queryEachbillsBigMoney(dateBean)方法来获取数据。请确保该方法返回的数据是正确的,并且包含了需要的series数据。 3. 循环逻辑错误:检查循环series的逻辑是否正确。请确保循环的起始和结束条件正确,并且循环体内的操作正确。 如果以上方法都没有解决问题,建议提供更多的代码或错误信息,以便更准确地定位问题所在。 #### 引用[.reference_title] - *1* [echarts绘制自定义tooltip、仪表盘、渐变双折线图](https://blog.csdn.net/qq_42248955/article/details/120405647)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [java 柱状图 折线图 resultType为map的数据解析](https://blog.csdn.net/cao2219600/article/details/84874993)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值