lineMarker.vue 5.19 KB
Newer Older
Pan's avatar
add  
Pan committed
1
<template>
Pan's avatar
Pan committed
2
  <div :class="className" :id="id" :style="{height:height,width:width}"></div>
Pan's avatar
add  
Pan committed
3
</template>
Pan's avatar
Pan committed
4

Pan's avatar
add  
Pan committed
5
<script>
Pan's avatar
Pan committed
6
import echarts from 'echarts'
Pan's avatar
add  
Pan committed
7

Pan's avatar
Pan committed
8
9
10
11
12
export default {
  props: {
    className: {
      type: String,
      default: 'chart'
Pan's avatar
Pan committed
13
    },
Pan's avatar
Pan committed
14
15
16
    id: {
      type: String,
      default: 'chart'
Pan's avatar
Pan committed
17
    },
Pan's avatar
Pan committed
18
19
20
    width: {
      type: String,
      default: '200px'
Pan's avatar
Pan committed
21
    },
Pan's avatar
Pan committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    height: {
      type: String,
      default: '200px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById(this.id))
Pan's avatar
add  
Pan committed
45

Pan's avatar
Pan committed
46
47
48
      this.chart.setOption({
        backgroundColor: '#394056',
        title: {
花裤衩's avatar
花裤衩 committed
49
50
          top: 20,
          text: 'Requests',
Pan's avatar
Pan committed
51
52
53
54
          textStyle: {
            fontWeight: 'normal',
            fontSize: 16,
            color: '#F1F1F3'
Pan's avatar
Pan committed
55
          },
花裤衩's avatar
花裤衩 committed
56
          left: '1%'
Pan's avatar
Pan committed
57
58
59
60
61
62
63
64
65
66
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            lineStyle: {
              color: '#57617B'
            }
          }
        },
        legend: {
花裤衩's avatar
花裤衩 committed
67
          top: 20,
Pan's avatar
Pan committed
68
69
70
71
          icon: 'rect',
          itemWidth: 14,
          itemHeight: 5,
          itemGap: 13,
花裤衩's avatar
花裤衩 committed
72
          data: ['CMCC', 'CTCC', 'CUCC'],
Pan's avatar
Pan committed
73
74
75
76
77
78
79
          right: '4%',
          textStyle: {
            fontSize: 12,
            color: '#F1F1F3'
          }
        },
        grid: {
花裤衩's avatar
花裤衩 committed
80
          top: 100,
Pan's avatar
Pan committed
81
82
          left: '3%',
          right: '4%',
花裤衩's avatar
花裤衩 committed
83
          bottom: '2%',
Pan's avatar
Pan committed
84
85
86
87
88
89
90
91
          containLabel: true
        },
        xAxis: [{
          type: 'category',
          boundaryGap: false,
          axisLine: {
            lineStyle: {
              color: '#57617B'
Pan's avatar
Pan committed
92
93
            }
          },
Pan's avatar
Pan committed
94
95
96
97
          data: ['13:00', '13:05', '13:10', '13:15', '13:20', '13:25', '13:30', '13:35', '13:40', '13:45', '13:50', '13:55']
        }],
        yAxis: [{
          type: 'value',
花裤衩's avatar
花裤衩 committed
98
          name: '(%)',
Pan's avatar
Pan committed
99
100
101
102
103
104
105
106
107
108
          axisTick: {
            show: false
          },
          axisLine: {
            lineStyle: {
              color: '#57617B'
            }
          },
          axisLabel: {
            margin: 10,
Pan's avatar
Pan committed
109
            textStyle: {
Pan's avatar
Pan committed
110
              fontSize: 14
Pan's avatar
Pan committed
111
112
            }
          },
Pan's avatar
Pan committed
113
114
115
116
117
118
119
          splitLine: {
            lineStyle: {
              color: '#57617B'
            }
          }
        }],
        series: [{
花裤衩's avatar
花裤衩 committed
120
          name: 'CMCC',
Pan's avatar
Pan committed
121
122
123
124
125
126
127
128
129
          type: 'line',
          smooth: true,
          symbol: 'circle',
          symbolSize: 5,
          showSymbol: false,
          lineStyle: {
            normal: {
              width: 1
            }
Pan's avatar
Pan committed
130
          },
Pan's avatar
Pan committed
131
132
133
134
135
136
137
138
139
140
141
          areaStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: 'rgba(137, 189, 27, 0.3)'
              }, {
                offset: 0.8,
                color: 'rgba(137, 189, 27, 0)'
              }], false),
              shadowColor: 'rgba(0, 0, 0, 0.1)',
              shadowBlur: 10
Pan's avatar
Pan committed
142
            }
Pan's avatar
Pan committed
143
144
145
146
147
148
          },
          itemStyle: {
            normal: {
              color: 'rgb(137,189,27)',
              borderColor: 'rgba(137,189,2,0.27)',
              borderWidth: 12
Pan's avatar
add  
Pan committed
149

Pan's avatar
Pan committed
150
151
152
153
            }
          },
          data: [220, 182, 191, 134, 150, 120, 110, 125, 145, 122, 165, 122]
        }, {
花裤衩's avatar
花裤衩 committed
154
          name: 'CTCC',
Pan's avatar
Pan committed
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
          type: 'line',
          smooth: true,
          symbol: 'circle',
          symbolSize: 5,
          showSymbol: false,
          lineStyle: {
            normal: {
              width: 1
            }
          },
          areaStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: 'rgba(0, 136, 212, 0.3)'
              }, {
                offset: 0.8,
                color: 'rgba(0, 136, 212, 0)'
              }], false),
              shadowColor: 'rgba(0, 0, 0, 0.1)',
              shadowBlur: 10
            }
          },
          itemStyle: {
            normal: {
              color: 'rgb(0,136,212)',
              borderColor: 'rgba(0,136,212,0.2)',
              borderWidth: 12
Pan's avatar
add  
Pan committed
183

Pan's avatar
Pan committed
184
185
186
187
            }
          },
          data: [120, 110, 125, 145, 122, 165, 122, 220, 182, 191, 134, 150]
        }, {
花裤衩's avatar
花裤衩 committed
188
          name: 'CUCC',
Pan's avatar
Pan committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
          type: 'line',
          smooth: true,
          symbol: 'circle',
          symbolSize: 5,
          showSymbol: false,
          lineStyle: {
            normal: {
              width: 1
            }
          },
          areaStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: 'rgba(219, 50, 51, 0.3)'
              }, {
                offset: 0.8,
                color: 'rgba(219, 50, 51, 0)'
              }], false),
              shadowColor: 'rgba(0, 0, 0, 0.1)',
              shadowBlur: 10
            }
          },
          itemStyle: {
            normal: {
              color: 'rgb(219,50,51)',
              borderColor: 'rgba(219,50,51,0.2)',
              borderWidth: 12
            }
          },
          data: [220, 182, 125, 145, 122, 191, 134, 150, 120, 110, 165, 122]
        }]
      })
Pan's avatar
add  
Pan committed
222
    }
Pan's avatar
Pan committed
223
  }
Pan's avatar
Pan committed
224
}
Pan's avatar
add  
Pan committed
225
</script>