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
| <template>
| <div class="data-chart-container">
| <el-card class="data-card" :body-style="{ height: '100%' }">
| <div class="card-content">
| <div class="title-container">
| <h1>运维监控报表</h1>
| <div class="select-container">
| <el-select v-model="company" placeholder="请选择运维公司">
| <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
| </el-option>
| </el-select>
| </div>
| <div class="date-container">
| <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期"
| end-placeholder="结束日期">
| </el-date-picker>
| </div>
| </div>
| <div class="chart-container">
| <div id="chartContent" ref="chartContent"></div>
| </div>
| </div>
| </el-card>
| </div>
| </template>
|
| <script>
| import * as echarts from 'echarts';
| let lineChart = null;
| export default {
| name: 'DataChart',
| data() {
| return {
| dateRange: '',
| company: '',
| options: [
| { label: 'XX运维公司1', value: 'XX运维公司1' },
| { label: 'XX运维公司2', value: 'XX运维公司2' },
| { label: 'XX运维公司3', value: 'XX运维公司3' },
| { label: 'XX运维公司4', value: 'XX运维公司4' },
| ],
| dataList: [
| {
| name: 'XX运维公司1',
| state: { '1月': 1000, '2月': 2131, '3月': 1233, '4月': 2132, '5月': 3211 },
| state2: { '1月': 123, '2月': 213, '3月': 1412, '4月': 23, '5月': 123 }
| },
| ],
| }
| },
| methods: {
| initChart() {
| const option = {
| legend: {
| right: '2%',
| top: '5%',
| icon: 'rect',
| data: [
| {
|
| name: '正常数',
| itemStyle: {
| color: 'rgba(62, 144, 247, 1)'
| }
| },
| {
| name: '异常数',
| itemStyle: {
| color: 'rgba(85, 192, 191, 1)'
| }
| },
| ],
| },
| grid: {
| left: 0,
| right: 0,
| bottom: 0,
| top: '20%',
| containLabel: true
| },
| tooltip: {},
| xAxis: {
| type: 'category',
| data: Object.keys(this.acitveData.state),
| },
| yAxis: {},
| series: [
| {
| name: '正常数',
| data: Object.entries(this.acitveData.state).map(([key, value]) => value),
| type: 'line',
| itemStyle: {
| color: 'rgba(62, 144, 247, 1)'
| }
| },
| {
| name: '异常数',
| data: Object.entries(this.acitveData.state2).map(([key, value]) => value),
| type: 'line',
| itemStyle: {
| color: 'rgba(85, 192, 191, 1)'
| }
| }
| ]
| };
| lineChart.setOption(option, true);
| },
|
| handleResize() {
| if (lineChart) {
| lineChart.resize()
| }
| }
|
| },
| mounted() {
| this.acitveData = this.dataList[0];
| lineChart = echarts.init(this.$refs.chartContent);
| this.initChart();
| window.addEventListener('resize', this.handleResize)
| },
| beforeDestroy() {
| window.removeEventListener('resize', this.handleResize)
| },
| }
| </script>
|
| <style lang="scss" scoped>
| .data-chart-container {
| height: 400px;
| margin-bottom: 20px;
|
| .data-card {
| height: 100%;
|
| .card-content {
| width: 100%;
| height: 100%;
| position: relative;
| }
| }
| }
|
| .title-container {
| position: absolute;
| display: flex;
| justify-content: space-between;
| align-items: center;
| z-index: 2;
|
|
| .more-button {
| cursor: pointer;
| font-size: 16px;
| padding: 0 10px;
| }
| }
|
| .chart-container {
|
| width: 100%;
| height: 100%;
|
| #chartContent {
| width: 100%;
| height: 100%;
| }
| }
|
| .select-container {
| margin: 0 20px;
| width: 180px;
| }
| </style>
|
|