fuliqi
2024-08-20 a6842851a844e63a8766d63c5410a8e2f27a7d45
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
132
133
134
135
136
137
138
139
140
141
142
143
<template>
  <div class="hola-container">
    <div class="chart" id="dataChart" ref="chartRef"></div>
  </div>
</template>
 
<script>
import * as echarts from 'echarts';
let myChart = null;
export default {
  name: 'DataHola',
  props: {
    centerValue: {
      type: Number,
      default: 0
    },
    holaColor: {
      type: String,
      default: '#4ea8ff'
    },
    holaTitle: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      
    }
  },
  methods: {
    initChart() {
      const series= [
        {
          type: 'gauge', // 仪表盘类型
          name: '系列名称', // 用于tooltip的显示
          startAngle: 90, // 仪表盘开始角度(设置背景圆的角度)
          endAngle: -270, // 仪表盘结束角度
          center: ['50%', '50%'], // 中心点(圆心坐标)
          radius: '100%', // 圆大小(仪表盘半径)
          clockwise: true, // 仪表盘刻度是否是顺时针增长
          // 仪表盘轴线相关配置
          axisLine: {
            show: true,
            roundCap: false, // 两端显示成圆形(背景环)
            clip: false, // 是否裁剪超出部分
            // 设置背景圆环样式
            lineStyle: {
              width: 6, // 圆环宽度
              color: [[1, '#002865']] // 圆环背景色
            }
          },
          max: 5000,
          // 仪表盘指针
          pointer: {
            show: false
          },
          // 进度设置
          progress: {
            show: true,
            overlap: false, // 多组数据时进度条是否重叠
            roundCap: true, // 是否在两端显示成圆形
            clip: false, // 是否裁掉超出部分
            // 进度条样式
            itemStyle: {
              borderWidth: 0,
              shadowColor: '',
              color: this.holaColor
            }
          },
          // 仪表盘分割线
          splitLine: {
            show: false
          },
          // 刻度样式
          axisTick: {
            show: false
          },
          // 刻度标签
          axisLabel: {
            show: false
          },
          title: {
            show: false,
            fontSize: 20
          },
          detail: {
            // width: 50,
            // height: 14,
            fontSize: 20,
            color: 'auto'
          },
          data: [
            {
              value: this.centerValue,
              name: this.holaTitle,
              title: {
                show: true,
                fontSize: 14,
                color: '#fff',
                offsetCenter: ['0%', '30%'],
              },
              detail: {
                fontSize: 18,
                // 中心title设置
                offsetCenter: ['0%', '-10%'],
                color: '#fff',
                formatter: '{value}'
 
              }
            }
          ],
        }
      ];
      myChart.setOption({
      series: series
    })
    }
  },
  mounted() {
    myChart = echarts.init(this.$refs['chartRef']);
    this.initChart();
  },
  watch: {
    centerValue() {
      myChart = echarts.init(this.$refs['chartRef']);
      this.initChart();
    }
  }
}
</script>
 
<style lang="scss" scoped>
.hola-container {
  width: 100%;
  height: 100%;
 
  .chart {
    width: 100%;
    height: 100%;
  }
}
</style>