riku
2025-07-23 3daf8eebf8c0d5b4561f38e21c50818c8f6768b7
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
<template>
  <div ref="gaugeChart" class="gauge-chart"></div>
</template>
<script>
import * as echarts from 'echarts';
import { gaugeOption } from '@/utils/chart/chart-option';
 
export default {
  props: {
    name: String,
    value: Number
  },
  data() {
    return {
      option: null
    };
  },
  watch: {
    value(nV) {
      this.refreshChart(nV);
    }
  },
  methods: {
    initChart() {
      this.option = gaugeOption(this.name, this.value);
      this.gaugeChart.setOption(this.option);
    },
    refreshChart(e) {
      this.option.series[0].data[0].value = e;
      this.gaugeChart.setOption(this.option);
    }
  },
  mounted() {
    this.gaugeChart = echarts.init(this.$refs.gaugeChart);
    this.initChart();
  }
};
</script>
<style scoped>
.gauge-chart {
  height: 280px;
  width: 260px;
  /* background-color: aliceblue; */
}
</style>