车辆管理系统-后台管理系统web
spring
4 天以前 9a11bff3d98aea29f37abc34a00a17f5c92ade9c
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<template>
  <div>
    <div :id="echarts" :style="styles"></div>
  </div>
</template>
 
<script>
  import echarts from 'echarts';
 
  export default {
    name: 'index',
    props: {
      // styles: {
      //   type: Object,
      //   default: null
      // },
      seriesData: {
        type: Array,
        default: () => []
      },
      xAxis: {
        type: Array,
        default: () => []
      },
      echartsTitle: {
        type: String,
        default: ''
      },
      yAxisData: {
        type: Array,
        default: () => []
      },
      legendData: {
        type: Array,
        default: () => []
      }
    },
    data() {
      return {
        styles: 'height:300px',
        infoLists: this.infoList,
        seriesArray: this.seriesData
      }
    },
    watch: {
      seriesData: {
        handler(newVal, oldVal) {
          this.seriesArray = newVal;
          this.handleSetVisitChart();
        },
        deep: true // 对象内部属性的监听,关键。
      }
    },
    computed: {
      echarts() {
        return 'echarts' + Math.ceil(Math.random() * 100)
      }
    },
    mounted: function () {
      const vm = this
      vm.$nextTick(() => {
        vm.handleSetVisitChart();
        window.addEventListener('resize', this.wsFunc)
      })
    },
    methods: {
      wsFunc() {
        this.myChart.resize()
      },
      handleSetVisitChart() {
        this.myChart = echarts.init(document.getElementById(this.echarts))
        let option = null
        if (this.echartsTitle === 'circle') {
          option = {
            tooltip: {
              trigger: 'item',
              formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
              orient: 'vertical',
              left: 'right',
              data: this.legendData || []
            },
            series: [
              {
                name: '访问来源',
                type: 'pie',
                radius: '70%',
                center: ['50%', '60%'],
                data: this.seriesArray || [],
                emphasis: {
                  itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              }
            ]
          };
        } else {
          option = {
            tooltip: {
              trigger: 'axis'
            },
            toolbox: {},
            legend: {
              data: this.legendData || []
            },
            color: ['#1495EB', '#00CC66', '#F9D249', '#ff9900', '#9860DF'],
            grid: {
              left: 16,
              right: 25,
              bottom: 10,
              top: 40,
              containLabel: true
            },
            xAxis: [
              {
                type: 'category',
                axisLine: {
                  lineStyle: {
                    color: '#D7DDE4'
                  }
                },
                axisTick: {
                  alignWithLabel: true,
                  lineStyle: {
                    color: '#D7DDE4'
                  }
                },
                splitLine: {
                  show: false,
                  lineStyle: {
                    color: '#F5F7F9'
                  }
                },
                // axisPointer: {
                //     type: 'shadow'
                // },
                axisLabel: {
                  interval: 0,
                  rotate: 40,
                  textStyle: {
                    color: '#7F8B9C'
                  }
                },
                data: this.xAxis
              }
            ],
            yAxis: this.yAxisData.length?this.yAxisData:{
              axisLine: {
                show: false
              },
              axisTick: {
                show: false
              },
              axisLabel: {
                textStyle: {
                  color: '#7F8B9C'
                }
              },
              splitLine: {
                show: true,
                lineStyle: {
                  color: '#F5F7F9'
                }
              },
              type: 'value'
            },
            series: this.seriesArray
          };
        }
 
        // 基于准备好的dom,初始化echarts实例
        this.myChart.setOption(option, true)
      },
      handleResize() {
        this.myChart.resize()
      }
    },
    beforeDestroy() {
      window.removeEventListener('resize', this.wsFunc)
      if (!this.myChart) {
        return
      }
      this.myChart.dispose()
      this.myChart = null
    }
  }
</script>
 
<style scoped>
 
</style>