echarts实现多环形图

echarts实现多环形

效果如下

在这里插入图片描述

<section class="attack-stage-wrapper">
      <div id="test" class="attack-stage-map"></div>
      <ul class="attack-stage-context">
        <li class="attack-stage-items" v-for="(item, index) in viewPanel" :key="item.name">
          <div :class="['items-label__context', item.symbol]">{{ item.name }}</div>
          <div class="items-label__extend">
            <span>{{ GLOBAL.formatTheThousandths(item.value) }}</span>
          </div>
        </li>
      </ul>
    </section>
<script>
import echarts from 'echarts';
import { attackRatio } from '@/api/dashboard';
import tableLoading from '@/components/loading/loading';
export default {
  components: {
    tableLoading
  },
  data() {
    return {
      viewPanel: [
        { symbol: 'dmz', value: 0, name: '暴露面攻击' },
        { symbol: 'transferAttack', value: 0, name: '中转区攻击' },
        { symbol: 'crossOut', value: 0, name: '横向移动(外)' },
        { symbol: 'fallOut', value: 0, name: '失陷回连(外)' },
        { symbol: 'crossIn', value: 0, name: '横向移动(内)' },
        { symbol: 'fallIn', value: 0, name: '失陷回连(内)' }
      ],
      dmzData: 0,
      transferAttackData: 0,
      crossOutData: 0,
      fallOutData: 0,
      crossInData: 0,
      fallInData: 0,
      dataArr: []
    };
  },
  mounted() {
    /**
      * 暴露面:expose: dmz
        中转区:expose: transferAttack
        横向移动外:expose: crossOut
        失陷回连外:expose: fallOut
        横向移动内:expose: crossIn
        失陷回连内:expose: fallIn
      */
    const exposeList = ['dmz', 'transferAttack', 'crossOut', 'fallOut', 'crossIn', 'fallIn'];
    this.$nextTick(() => {
      exposeList.forEach(val => {
        this.getData(val);
      });
    });
  },
  methods: {
    async getData(val) {
      const BarBOX1 = echarts.init(document.getElementById('test'));
      const res = await attackRatio(val);
      if (res.data.code === 200) {
        switch (val) {
          case 'dmz':
            this.dmzData = res.data.data;
            break;
          case 'transferAttack':
            this.transferAttackData = res.data.data;
            break;
          case 'crossOut':
            this.crossOutData = res.data.data;
            break;
          case 'fallOut':
            this.fallOutData = res.data.data;
            break;
          case 'crossIn':
            this.crossInData = res.data.data;
            break;
          case 'fallIn':
            this.fallInData = res.data.data;
            break;
        }
        const chartData = [
          { value: this.dmzData, name: '测试1', symbol: 'dmz' },
          { value: this.transferAttackData, name: '测试2', symbol: 'transferAttack' },
          { value: this.crossOutData, name: '测试3', symbol: 'crossOut' },
          { value: this.fallOutData, name: '测试4', symbol: 'fallOut' },
          { value: this.crossInData, name: '测试5', symbol: 'crossIn' },
          { value: this.fallInData, name: '测试6', symbol: 'fallIn' }
        ];
        this.viewPanel = chartData;
        const arrName = [];
        const arrValue = [];
        chartData.forEach((v, i) => {
          arrName.push(v.name);
          arrValue.push(v.value);
        });
        const placeItemStyle = {
          normal: {
            label: {
              show: false,
              position: 'center'
            },
            labelLine: {
              show: false
            },
            color: '#FAFAFA',
            borderColor: '#FAFAFA',
            borderWidth: 2
          },
          emphasis: {
            color: '#FAFAFA',
            borderColor: '#FAFAFA',
            borderWidth: 2
          }
        };
        BarBOX1.setOption({
          // yAxis: {},
          backgroundColor: 'white',
          series: [
            {
              color: '#1890FF',
              name: '测试1',
              type: 'pie',
              radius: ['75%', '70%'],
              hoverAnimation: false, // 鼠标移入变大
              label: {
                normal: {
                  show: false
                }
              },
              labelLine: {
                normal: {
                  show: false
                }
              },
              data: [{
                value: this.dmzData,
                name: '测试1'
              },
              {
                value: 5,
                name: '',
                itemStyle: placeItemStyle
              }
              ]
            },
            {
              name: '测试2',
              type: 'pie',
              color: '#13C2C2',
              radius: ['65%', '60%'],
              hoverAnimation: false, // 鼠标移入变大
              label: {
                normal: {
                  show: false
                }
              },
              labelLine: {
                normal: {
                  show: false
                }
              },

              data: [{
                value: this.transferAttackData,
                name: '测试2'
              },
              {
                value: 5,
                name: '',
                itemStyle: placeItemStyle
              }
              ]
            },
            {
              name: '测试3',
              type: 'pie',
              color: '#2FC25B',
              radius: ['55%', '50%'],
              hoverAnimation: false, // 鼠标移入变大
              label: {
                normal: {
                  show: false
                }
              },
              labelLine: {
                normal: {
                  show: false
                }
              },

              data: [{
                value: this.crossOutData,
                name: '测试3'
              },
              {
                value: 5,
                name: '',
                itemStyle: placeItemStyle
              }
              ]
            },
            {
              name: '测试4',
              type: 'pie',
              color: '#FB65B7',
              radius: ['45%', '40%'],
              hoverAnimation: false, // 鼠标移入变大
              label: {
                normal: {
                  show: false
                }
              },
              labelLine: {
                normal: {
                  show: false
                }
              },

              data: [{
                value: this.fallOutData,
                name: '测试4'
              },
              {
                value: 5,
                name: '',
                itemStyle: placeItemStyle
              }
              ]
            },
            {
              name: '测试5',
              type: 'pie',
              color: '#FF9700',
              radius: ['35%', '30%'],
              hoverAnimation: false, // 鼠标移入变大
              label: {
                normal: {
                  show: false
                }
              },
              labelLine: {
                normal: {
                  show: false
                }
              },

              data: [{
                value: this.crossInData,
                name: '测试5'
              },
              {
                value: 5,
                name: '',
                itemStyle: placeItemStyle
              }
              ]
            },
            {
              name: '测试6',
              type: 'pie',
              color: '#F9D236',
              radius: ['25%', '20%'],
              hoverAnimation: false, // 鼠标移入变大
              label: {
                normal: {
                  show: false
                }
              },
              labelLine: {
                normal: {
                  show: false
                }
              },

              data: [{
                value: this.fallInData,
                name: '测试6'
              },
              {
                value: 5,
                name: '',
                itemStyle: placeItemStyle
              }
              ]
            }
          
          ]
        });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.attack-stage-wrapper{
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 400px;
  height: 320px;
  .attack-stage-map{
    width: 280px;
    height: 280px;
  }
  .attack-stage-context{
    font-size: 14px;
    color: #919398;
  }
  .attack-stage-items{
    display: flex;
    align-items: center;
    height: 24px;
    margin-bottom: 8px;
    width: 190px;
    overflow: hidden;
    .items-label__context{
      flex: 1;
      font-size: 14px;
      color: #919398;
      padding-left: 16px;
      position: relative;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      &::before{
        content: '';
        display: block;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        position: absolute;
        left: 0;
        top: 50%;
        margin-top: -4px;
        background-color: #1890FF;
      }
      &.dmz{
        &::before{
          background-color: #1890FF;
        }
      }
      &.transferAttack{
        &::before{
          background-color: #13C2C2;
        }
      }
      &.crossOut{
        &::before{
          background-color: #2FC25B;
        }
      }
      &.fallOut{
        &::before{
          background-color: #FB65B7;
        }
      }
      &.crossIn{
        &::before{
          background-color: #FF9700;
        }
      }
      &.fallIn{
        &::before{
          background-color: #F9D236;
        }
      }
    }
    .items-label__extend{
      text-align: right;
      font-size: 14px;
      color: #303133;
    }
  }
}
</style>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值