拖旺项目:聊城公交辅助决策系统
master
2022-04-27 493930a42a2ea3e13905ffd8772cdb945baa7bcf
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
<template>
  <div :id="id" style="width: 100%;" :style="{height:height}"></div>
</template>
 
<script>
import * as echarts from "echarts";
export default {
  name: "charts",
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    option: {
      type: Number,
      default(){
        return 16
      }
    },
  },
  data() {
    return {
      chart: "",
 
    };
  },
 
  watch: {
    option: {
      handler(newVal, oldVal) {
        if(newVal && this.chart){
          this.chart.setOption(this.initOption())
        }
      },
      deep: true,
    },
  },
  created() {
  },
  mounted() {
    this.init();
  },
  methods: {
    initOption(){
      let that = this;
      let colort = "#13E8DE"
      if(that.id == "fgsg4"){
        if(that.option > 80){
          colort = "#E04659"
        } else if(that.option > 40) {
          colort = "#0286FF"
        } else if(that.option < 40) {
          colort = "#13E8DE"
        }
      } else {
        if(that.option > 80){
          colort = "#13E8DE"
        } else if(that.option > 40) {
          colort = "#0286FF"
        } else if(that.option < 40) {
          colort = "#E04659"
        }
      }
 
      return {
        series: [
          {
            type: 'gauge',
            progress: {
              show: true,
              width: 5,
              itemStyle: {
                color: colort
              }
            },
            axisLine: {
              lineStyle: {
                width: 5,
                color:[[1, '#1F3445']]
              }
            },
            axisTick: {
              show: false
            },
            pointer: {
              show: false
            },
            splitLine: {
              show:false,
              length: 15,
              lineStyle: {
                width: 2,
                color: '#999'
              }
            },
            axisLabel: {
              show:false,
            },
            anchor: {
              show: false,
 
            },
            title: {
              show: false
            },
 
            detail: {
              show: true,
              padding:[-55,0,0,0],
              valueAnimation:true,
              offsetCenter: [0, '70%'],
              fontSize: 33,
              formatter: val => {
                return `{a|${val}%}`
              },
              rich: {
                a: {
                  fontSize: 20,
                  fontFamily:'Digital',
                  color: colort,
                },
                b: {
                  fontSize: 24,
                  // color: 'red',
                }
              },
            },
            data: [
              {
                value: that.option
              }
            ]
          }
        ]
      };
    },
    init() {
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption(this.initOption());
      window.addEventListener('resize', this.chart.resize)
    },
  },
};
</script>