关于Echarts饼图循环series里data

12,820次阅读
没有评论

共计 1819 个字符,预计需要花费 5 分钟才能阅读完成。

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

关于 Echarts 饼图循环 series 里 data

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

 var myChart4 = echarts.init(this.$refs.myChart4)
      var series=[]
      for (var i=0,len=this.ytgsList.length;i

第二步:直接创建 此处 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();});

整体如下

原文地址: 关于 Echarts 饼图循环 series 里 data

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-10-07发表,共计1819字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)