Echarts升级7:环状图+标题设置+legend属性

 效果

注意的点:

  • title样式
  • 颜色设置
  • legend颜色设置
  • legend   textStyle 样式设置;formatter样式设置,文字拆分

 代码:

<template>
  <div style="width: 100%; height: 100%;">
    <div id="siteStatusStatisticChart" style="width: 100%; height: 100%;"></div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        allItem: [{
            name: '在线',
            value: 1424,
          },
          {
            name: '离线',
            value: 314,
          },
          {
            name: '维护',
            value: 513,
          },
        ],
      }
    },
    mounted() {
      this.initChart()
    },
    methods: {
      // getSelectAreaData(obj) {
      //     this.getRealDatas(obj)
      //   },
      //初始化echart
      initChart() {
        let chartDom = document.getElementById("siteStatusStatisticChart");
        this.myChart = this.echarts.init(chartDom);
        let sum = this.allItem.reduce((cur, pre) => {
          return cur + pre.value;
        }, 0);
        let dataline = [];
        let legendData = [];
        var color = [
          '#00FFFF',
          '#006CED',
          '#FFE000',
        ];
        for (var i = 0; i < this.allItem.length; i++) {
          let name = this.allItem[i].name + '/' + this.allItem[i].value;
          legendData.push(name);
          dataline.push({
            value: this.allItem[i].value,
            name: name,
            itemStyle: {
              borderWidth: 0,
              borderRadius: 5,
              shadowBlur: 10,
              borderColor: color[i],
              shadowColor: color[i],
            },
          }, {
            value: sum / 100, // 控制每个环形之间的间隙
            name: '',
            itemStyle: {
              label: {
                show: false,
              },
              labelLine: {
                show: false,
              },
              color: 'rgba(0, 0, 0, 0)',
              borderColor: 'rgba(0, 0, 0, 0)',
              borderWidth: 0,
            },
          });
        }
        let option = {
          title: {
            text: `{title|${sum}}\n{subtitle|站点总数}`,
            x: '17%',
            y: 'center',
            textStyle: {
              rich: {
                title: {
                  color: '#00FFFF',
                  fontSize: 31,
                  fontWeight: 'normal',
                  fontWeight: 'bold',
                  align: 'center',
                },
                subtitle: {
                  fontSize: 14,
                  color: '#00FFFF',
                  fontFamily: 'HarmonyOS Sans SC',
                  fontWeight: '400',
                  align: 'center',
                },
              }
            }
          },
          // title: [{
          //     text: sum,
          //     x: '18%',
          //     top: '38%',
          //     textStyle: {
          //      color: '#00FFFF',
          //      fontSize: 31,
          //      fontWeight: 'normal',
          //      fontWeight: 'bold',
          //     },
          //   },
          //   {
          //     text: '站点总数',
          //     x: '19%',
          //     top: '53%',
          //     textStyle: {
          //       fontSize: 14,
          //       color: '#00FFFF',
          //       fontFamily: 'HarmonyOS Sans SC',
          //       fontWeight: '400',
          //     },
          //   },
          // ],
          color: color,
          tooltip: {
            show: false,
          },
          legend: {
            icon: 'rect',
            itemWidth: 5,
            itemHeight: 5,
            itemStyle: {
              borderWidth: 3
            },
            orient: 'vertical',
            data: legendData,
            right: '12%',
            top: 'center',
            align: 'left',
            textStyle: {
              rich: {
                numStyle0: {
                  padding: [3, 0, 0, 8],
                  fontSize:30,
                  color: '#00FFFF',
                  fontWeight: 600,
                },
                numStyle1: {
                  padding: [3, 0, 0, 8],
                  fontSize: 30,
                  color: '#006CED',
                  fontWeight: 600,
                },
                numStyle2: {
                  padding: [3, 0, 0, 8],
                  fontSize:30,
                  color: '#FFE000',
                  fontWeight: 600,
                },
                nameStyle: {
                  padding: [3, 0, 0, 8],
                  verticalAlign: 'right',
                  align: 'left',
                  width: 60,
                  fontSize: 12,
                  color: '#ffffff',
                  fontWeight: 400,
                },
              },
            },
            formatter: name => {
              for (let i = 0; i < legendData.length; i++) {
                if (name == legendData[i]) {
                  return `{numStyle${i}|${name.substring(name.indexOf("\/")+1,name.length)}}\n{nameStyle|${name.substring(0,name.indexOf("/"))}}`
                }
              }
            },
            itemGap: 20, // 图例之间的间隔
          },
          toolbox: {
            show: false,
          },
          series: {
            type: 'pie',
            clockwise: false, //旋转顺序
            radius: ['60%', '80%'],
            center: ['25%', '50%'],
            emphasis: {
              scale: false,
            },
            label: {
              show: false,
            }, //箭头
            data: dataline,
          },
        };
        this.myChart.setOption(option)
      },
    }
  }

</script>
<style scoped>

</style>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Echarts环状是一种常用的表模板之一,可以用于展示数据的占比关系。根据引用\[1\]中的内容,Echarts环状可以通过配置来实现不同的效果,比如环形环形占比等。在引用\[2\]中的代码示例中,可以看到如何自定义右侧legend的颜色和样式。通过设置legend的formatter属性,可以自定义每个例项的显示内容和样式。在引用\[3\]中的代码示例中,展示了一个女生占比的环状。通过设置series的type为'pie',可以创建一个饼,通过设置radius属性可以调整内外半径,从而实现环状的效果。同时,可以通过设置label的formatter属性来自定义标签的显示内容和样式。 #### 引用[.reference_title] - *1* *2* [echarts 环形](https://blog.csdn.net/aibujin/article/details/124796709)[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^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [【ECharts环形、饼状](https://blog.csdn.net/wuli_youhouli/article/details/124078034)[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^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BMG-Princess

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值