echart-pie.vue 2.93 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
<script setup>
const state=reactive({
  chartData:{
    legend:['軟件','硬件','服務','安全','廣告'],
    colors:[$c.bll5,$c.inl3,$c.aql3,$c.yel3,$c.orl3,$c.rel3],
    data:[325,252,323,183,120,43]
  },
  counter:{title:"费用总量",num:1723},
  chartOption:{}
})

const processData=()=>{
  let {legend,colors,data}=state.chartData,
      processedData=[]
  legend.forEach((item,i)=>{
    processedData.push({
      value:data[i],
      name:legend[i],
      itemStyle:{
        color:colors[i]
      }
    })
  })
  state.chartOption.series[0].data=processedData;
  state.chartOption.legend.data=legend;
}

const processOption=()=>{
  state.chartOption={
    update:false,
    title:{
      show:false,
      text:"",
      x:'center',
      top:'32%',
      textStyle:{
        color:$c.bll5,
        fontSize:24,
        fontWeight:"bold",
        lineHeight:30
      },
    },
    tooltip: {
      trigger: 'item',
      formatter: "{a} <br/>{b}: {c} ({d}%)"
    },
    legend: {
      orient: 'vertical',//horizontal
      show:true,
      right: '40',
      top:'22%',
      data:[],
      formatter:(name)=>{
        let target;
        for(let i=0;i<state.chartData.data.length;i++){
          if(state.chartData.legend[i]==name){
            target=state.chartData.data[i]
          }
        }
        
        return "{a|"+name+"}"+" "+"{b|"+target+"}"
      },
      textStyle:{
        rich:{
          a:{
              fontSize:14,
              color:$c.bll5,
              padding:10
          },
          b:{
              fontSize:16,
              color:$c.cyl5
          }
        }
      }
    },
    series: [
      {
        name:'数据类别',
        type:'pie',
        radius: ['55%', '80%'],
        center: ['30%', '50%'],
        //roseType: 'radius',
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: 'outside',
        },
        itemStyle: {
            borderRadius: 10,
            borderColor: $c.bll9,
            borderWidth: 5
        },
        emphasis: {
          label:{
            show: false,
            fontSize: '20',
            color:$c.gyd5,
          }
        },
        labelLine: {
          show: false
        },
        data:[]
      }
    ]
  }
  processData()
}

onMounted(() => {
  processOption();
})
</script>
<template>
  <div class="echart-wrap-dashB">
    <div class="total-digital">
      <span class="desc">{{state.counter.title}}</span>
      <DigitalTransform  class="counter" :value="state.counter.num" :interval="1000" :dislocation="false" ></DigitalTransform>
    </div>
    <echartsInit :chartOption="state.chartOption"></echartsInit>
  </div>
</template>
<style lang="less">
.echart-wrap-dashB{height: 100%;
  .total-digital{.fc(@cyl5); text-align: center; width: 100px;  .poa; top:52%; left:19%; .fixc("y");
    .desc{display:block; font-size: 18px; margin:0 0 10px 0;}
    .counter{display:block; .ff("en0"); font-size: 24px; font-weight: bold;}
  }
}
</style>