vue实现 【echarts中 “1种” Sunburst旭日图图例】的组件封装及调用

echarts组件使用参考:https://blog.csdn.net/weixin_50450473/article/details/121510438

图例一:

图例一

let datas = [
  {
    AvgScore: 4.5,
    SumAvdScore: 6.5,
    Title: '积极低唤醒',
    Children: [
      {
        AvgScore: 17.6,
        SumAvdScore: 6.5,
        Title: '满足'
      },
      {
        AvgScore: 17.6,
        SumAvdScore: 6.5,
        Title: '平静'
      },
      {
        AvgScore: 17.6,
        SumAvdScore: 6.5,
        Title: '放松'
      }
    ]
  },
  {
    AvgScore: 4.5,
    SumAvdScore: 6.5,
    Title: '积极高唤醒',
    Children: [
      {
        AvgScore: 17.6,
        SumAvdScore: 6.5,
        Title: '自豪'
      },
      {
        AvgScore: 15.6,
        SumAvdScore: 6.5,
        Title: '希望'
      },
      {
        AvgScore: 24.1,
        SumAvdScore: 6.5,
        Title: '高兴'
      }
    ]
  },
  {
    AvgScore: 4.5,
    SumAvdScore: 6.5,
    Title: '消极高唤醒',
    Children: [
      {
        AvgScore: 17.6,
        SumAvdScore: 6.5,
        Title: '羞愧'
      },
      {
        AvgScore: 15.6,
        SumAvdScore: 6.5,
        Title: '焦虑'
      },
      {
        AvgScore: 24.1,
        SumAvdScore: 6.5,
        Title: '生气'
      }
    ]
  },
  {
    AvgScore: 4.5,
    SumAvdScore: 6.5,
    Title: '消极低唤醒',
    Children: [
      {
        AvgScore: 17.6,
        SumAvdScore: 6.5,
        Title: '无助'
      },
      {
        AvgScore: 15.6,
        SumAvdScore: 6.5,
        Title: '沮丧'
      },
      {
        AvgScore: 24.1,
        SumAvdScore: 6.5,
        Title: '厌倦'
      },
      {
        AvgScore: 24.1,
        SumAvdScore: 6.5,
        Title: '心烦-疲乏'
      }
    ]
  }
];
let fatherName = [];
datas.forEach((ma, index) => {
  let a = JSON.parse(
    JSON.stringify(ma.Children)
      .replace(/SumAvdScore/g, 'value')
      .replace(/Title/g, 'name')
      .replace(/AvgScore/g, 'avg')
  );
  fatherName.push({
    name: ma.Title,
    avg: ma.AvgScore,
    realvalue: ma.SumAvdScore,
    children: a
  });
});
option = {
  color: ['#326092', '#2c7eeb', '#d5f1ff', '#3dc6c8', '#becae0', '#4d8fc6'],
  series: [
    {
      type: 'sunburst',
      radius: [0, '100%'],
      itemStyle: {
        normal: {
          label: {
            position: 'inner',
            formatter: function (params) {
              if (params.data.realvalue) {
                return (
                  params.data.name +
                  '\n你的得分:' +
                  params.data.realvalue +
                  '\n平均得分:' +
                  params.data.avg
                );
              } else {
                return (
                  params.data.name +
                  '\n你的得分:' +
                  params.data.value +
                  '\n平均得分:' +
                  params.data.avg
                );
              }
            },
            fontSize: 13,
            lineHeight: 20
          }
        }
      },
      labelLine: {
        // 显示刻度线条
        normal: {
          show: true,
          lineStyle: {
            color: '#333'
          }
        }
      },
      levels: [
        {},
        {
          r0: '0%',
          r: '70%',
          label: {
            rotate: 0 //旋转角度
            // rotate: 'tangential'  // 跟随图形旋转角度
          }
        },
        {
          r0: '70%',
          r: '85%',
          label: {
            position: 'outside',
            padding: 10,
            rotate: 0,
            silent: false
          }
        }
      ],
      data: fatherName
    }
  ]
};

      希望我的愚见能够帮助你哦~,若有不足之处,还望指出,你们有更好的解决方法,欢迎大家在评论区下方留言支持,大家一起相互学习参考呀~

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值