zmc
2023-08-07 1e18f0bcee0358e13c0e2cb750d17cd7ef5bf4d6
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
<template>
    <div ref="chart" :style="{ width: chartSize, height: chartSize }" class="gauge-chart"></div>
  </template>
  
  <script>
  import * as echarts from 'echarts';
  
  export default {
    props: {
      styleDashB: {
        type: String,
        required: true
      }
    },
    data() {
      return {
        chart: null,
        chartSize: '200px'
      };
    },
    mounted() {
      this.renderChart();
      
      watchEffect(() => {
        this.resizeChart();
      });
    },
    methods: {
      renderChart() {
        this.chart = echarts.init(this.$refs.chart);
  
        const chartOptions = {
          series: [
            {
              type: 'gauge',
              data: [{ value: 50, name: 'value' }]
            }
          ]
        };
  
        this.chart.setOption(chartOptions);
      },
      resizeChart() {
        const newSize = this.styleDashB !== 'small' ? (this.styleDashB === 'large' ? '600px' : '400px') : '200px';
        this.chartSize = newSize;
        this.chart.resize();
      }
    }
  };
  </script>
  
  <style>
  .gauge-chart {
    height: 300px;
    margin-top: 20px;
  }
  </style>