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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
| <template>
| <div style="width: 100%">
| <el-card class="box-card">
| <div slot="header" class="clearfix">
| <span style="font-weight: 600; font-size: 20px">响应支持类统计</span>
| <div class="card-title-right">
| <div :style="{ color: weekFlag ? '#378cff' : '' }" @click="changeDate(1)">近7天</div>
| <div :style="{ color: monthFlag ? '#378cff' : '' }" style="margin: 0 30px 0 10px" @click="changeDate(2)">
| 近30天
| </div>
| <el-date-picker
| v-model="value2"
| type="daterange"
| :picker-options="pickerOptions"
| range-separator="至"
| start-placeholder="开始日期"
| end-placeholder="结束日期"
| align="right"
| value-format="yyyyMMdd"
| />
| <el-button type="primary" style="margin-left: 10px" @click="getCenterLine">搜索</el-button>
| </div>
| </div>
| <div id="main1" />
| </el-card>
| </div>
| </template>
| <script>
| import * as echarts from 'echarts';
|
| export default {
| name: 'XYZC',
| props: {
| activeId: {
| type: String,
| default: '',
| },
| },
| data() {
| return {
| pickerOptions: {
| shortcuts: [
| {
| text: '最近一周',
| onClick(picker) {
| const end = new Date();
| const start = new Date();
| start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
| picker.$emit('pick', [start, end]);
| },
| },
| {
| text: '最近一个月',
| onClick(picker) {
| const end = new Date();
| const start = new Date();
| start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
| picker.$emit('pick', [start, end]);
| },
| },
| {
| text: '最近三个月',
| onClick(picker) {
| const end = new Date();
| const start = new Date();
| start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
| picker.$emit('pick', [start, end]);
| },
| },
| ],
| },
| value2: '',
| myChart: null,
| weekFlag: 1, // 近七天
| monthFlag: null, // 近30天
| options: {},
| };
| },
| mounted() {
| this.getCenterLine();
| // 监听屏幕宽度变化:当浏览器发生resize事件的时候,触发echart的resize事件,重绘canvas
| window.addEventListener('resize', () => {
| this.changeWidth();
| });
| },
| methods: {
| changeDate(type) {
| if (type == 1) {
| this.monthFlag = null;
| if (this.weekFlag) {
| this.weekFlag = null;
| } else {
| this.weekFlag = 1;
| }
| if (this.weekFlag) {
| this.monthFlag = null;
| this.value2 = [];
| }
| this.getCenterLine();
| }
| if (type == 2) {
| this.weekFlag = null;
| if (this.monthFlag) {
| this.monthFlag = null;
| } else {
| this.monthFlag = 1;
| }
| if (this.monthFlag) {
| this.weekFlag = null;
| this.value2 = [];
| }
| this.getCenterLine();
| }
| },
| getCenterLine() {
| // getCenterLine({
| // id: this.activeId,
| // weekFlag: this.weekFlag,
| // monthFlag: this.monthFlag,
| // startDay: this.value2 ? this.value2[0] : null,
| // endDay: this.value2 ? this.value2[1] : null
| // }).then(res => {
| // const data = res.data
| var chartDom = document.getElementById('main1');
| this.myChart = echarts.init(chartDom);
| this.options = {
| color: ['#ED653B', '#1877FF'],
| tooltip: {
| trigger: 'axis',
| axisPointer: {
| type: 'shadow',
| },
| },
| legend: {
| data: ['响应速度', '处理速度'],
| },
| toolbox: {
| show: true,
| orient: 'vertical',
| left: 'right',
| top: 'center',
| feature: {
| mark: { show: true },
| dataView: { show: true, readOnly: false },
| magicType: { show: true, type: ['line', 'bar', 'stack'] },
| restore: { show: true },
| saveAsImage: { show: true },
| },
| },
| xAxis: [
| {
| type: 'category',
| axisTick: { show: false },
| data: [
| '12-01',
| '12-02',
| '12-03',
| '12-04',
| '12-05',
| '12-06',
| '12-07',
| '12-08',
| '12-09',
| '12-10',
| '12-11',
| '12-12',
| ],
| },
| ],
| yAxis: [
| {
| type: 'value',
| },
| ],
| dataZoom: [
| {
| orient: 'horizontal',
|
| show: true, //控制滚动条显示隐藏
|
| realtime: true, //拖动滚动条时是否动态的更新图表数据
|
| height: 15, //滚动条高度
|
| start: 0, //滚动条开始位置(共100等份)
| //
| // end: 30, //滚动条结束位置
| bottom: '4%',
| zoomLock: true, //控制面板是否进行缩放
| }
| ],
|
| series: [
| {
| name: '响应速度',
| type: 'line',
| barGap: 0,
| smooth: true,
| emphasis: {
| focus: 'series',
| },
| data: [320, 332, 301, 334, 320, 332, 301, 334, 320, 332, 301, 334],
| },
| {
| name: '处理速度',
| type: 'line',
| smooth: true,
| emphasis: {
| focus: 'series',
| },
| data: [220, 182, 191, 234, 220, 182, 191, 234, 220, 182, 191, 234],
| },
| ],
| };
|
| this.options && this.myChart.setOption(this.options);
| // });
| },
| changeWidth() {
| this.myChart.resize();
| },
| },
| };
| </script>
| <style lang="scss" scoped>
| #main1 {
| width: 100%;
| height: 400px;
| }
|
| .box-card {
| margin-top: 10px;
| width: 100%;
| border-radius: 10px;
| border: none;
| .card-title-right {
| display: flex;
| align-items: center;
| align-self: flex-end;
| float: right;
| }
| }
| </style>
|
|