独墅湖高教创新区危化品智慧管控平台(新危化品)
马宇豪
2025-04-22 91f2640c8919e7cbe41c8c437e4f7fd60345e062
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
<template>
  <div class="charts-container">
    <div id="typePie"></div>
  </div>
</template>
<script setup>
import * as echarts from 'echarts';
import {onMounted} from "vue";
import {ElMessage} from "element-plus";
import {getBasicCount} from "@/api/monitor/screenCharts";
 
onMounted(()=>{
  getPieData()
})
 
const getPieData = async ()=>{
  const res = await getBasicCount()
  if (res.code == 200) {
    if(res.data && Array.isArray(res.data) && res.data.length>0){
      let data = res.data.map(i=>{
        return {
          name: i.hazmatCharacter,
          value: i.count,
        }
      })
      initChart(data)
    }else{
      initChart([])
    }
  } else {
    ElMessage.warning(res.message)
  }
}
 
const initChart =(data)=>{
  var chartDom = document.getElementById('typePie');
  var myChart = echarts.init(chartDom);
  var option;
 
  option = {
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    legend: {
      left: 'center',
      bottom: '0',
      textStyle: {
        color: 'rgba(255,255,255,.6)'
      }
    },
    textStyle:{
      textBorderWidth: 0,
    },
    series: [
      {
        type: 'pie',
        radius: [20, 100],
        center: ['50%', '40%'],
        roseType: 'area',
        itemStyle: {
          borderRadius: 5
        },
        label: {
          color: '#fff',
          textBorderWidth: 0,
          formatter: '{d}%'
        },
        data: data
      }
    ]
  };
 
  option && myChart.setOption(option);
}
 
</script>
 
<style lang="postcss" scoped>
.charts-container{
  width: 100%;
  height: 100%;
}
 
#typePie{
  width: 100%;
  height: 100%;
}
</style>