xiangpei
2024-04-07 b2ef755893a694ea07b7ca2f46e4571bbc8e9cb9
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<template>
  <!-- 进度条类型组件 -->
  <div class="progressChart">
    <div class="chart" id="progressChart" ref="chartRef"></div>
    <el-link class="bottom le-0-font" :underline="false" @click="handleDetail(routerPath)">
    <label >{{ bottomTitle }}</label>
    </el-link>
  </div>
</template>
<script>
import * as echarts from 'echarts';
export default {
  data() {
    return {
      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: 10, // 圆环宽度
              color: [[1, '#002865']] // 圆环背景色
            }
          },
          // 仪表盘指针
          pointer: {
            show: false
          },
          // 进度设置
          progress: {
            show: true,
            overlap: false, // 多组数据时进度条是否重叠
            roundCap: true, // 是否在两端显示成圆形
            clip: false, // 是否裁掉超出部分
            // 进度条样式
            itemStyle: {
              borderWidth: 0,
              shadowColor: '',
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: this.startColor // 0% 处的颜色  '#02C77E'
                  },
                  {
                    offset: 1,
                    color: this.endColor // 100% 处的颜色  '#017770'
                  }
                ],
                global: false // 缺省为 false
              }
            }
          },
          // 仪表盘分割线
          splitLine: {
            show: false
          },
          // 刻度样式
          axisTick: {
            show: false
          },
          // 刻度标签
          axisLabel: {
            show: false
          },
          title: {
            show: false,
            fontSize: 24
          },
          detail: {
            // width: 50,
            // height: 14,
            fontSize: 14,
            color: 'auto'
          },
          data: [
            {
              value: this.centerValue,
              name: '345',
              title: {},
              detail: {
                // 中心title设置
                offsetCenter: ['0%', '0%'],
                color: '#01F8FF',
                formatter: '{value}%'
                // borderColor: '#01F8FF',
                // borderRadius: 20,
                // borderWidth: 1,
              }
            }
          ],
        }
      ]
    }
  },
  setup() { },
  props: {
    startColor: {
      type: String,
      default: ''
    },
    endColor: {
      type: String,
      default: ''
    },
    centerValue: {
      type: [Number, String],
      default: 0
    },
    routerPath: {
      type: String,
      default: ''
    },
    bottomTitle: {
      type: String,
      default: ''
    }
  },
  methods: {
    handleDetail(routerUrl) {
      this.$router.push({
        path: routerUrl,
      })
    }
  },
  created() { },
  mounted() {
    let myChart = echarts.init(this.$refs['chartRef']) // 使用Id无法实现
    myChart.setOption({
      series: this.series
    })
  }
}
</script>
<style lang="scss" scoped>
.progressChart {
  width: 100%;
  height: 100%;
 
  .chart {
    width: 100%;
    height: 75%;
  }
 
  .bottom {
    display: inline-block;
    width: 100%;
    color: #01f8ff;
    text-align: center;
    font-size: 16px;
    margin-top: 10px;
  }
}
</style>