-
Notifications
You must be signed in to change notification settings - Fork 0
/
markline2.html
363 lines (311 loc) · 11.2 KB
/
markline2.html
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- 引入 ECharts 文件 -->
<script src="echarts.min.js"></script>
</head>
<body>
<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
<div id="main1" style="width: 600px;height:400px;"></div>
<div id="main2" style="width: 600px;height:400px;"></div>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script>
//<!--运营能耗分类预警-->
var myChart1 = echarts.init(document.getElementById('main1'));
var data1 = ['10.2', '8.6', '9.3', '7.5']; //预警值 数组
var seriesData = [12, 7.8, 14.2, 6.2]; //总能耗数值数组
option1 = {
title: {
text: '分车型能耗预警'
},
color: ['#e7505a'],
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [{
type: 'category',
data: ['伊兰特汽油', '伊兰特CNG', 'B50汽油', '凯美瑞混合动力'],
axisTick: {
alignWithLabel: true
}
}],
yAxis: [{
type: 'value',
name: '百公里能耗L/100KM',
min: 0,
max: 15,
interval: 3,
axisLabel: {
formatter: '{value}'
}
}],
series: [{
name: '',
type: 'bar',
barWidth: '45%',
data: seriesData,
markLine: {
itemStyle: {
normal: {
borderWidth: 1,
lineStyle: {
type: 'dash',
color: '#333 ',
width: 2,
},
label: {
formatter: '',
textStyle: {
fontSize: 16,
fontWeight: "bolder",
},
}
},
},
data: [
[{
coord: ['伊兰特汽油', 0]
}, {
coord: ['伊兰特汽油', 10.2]
}],
[{
coord: ['伊兰特CNG', 0]
}, {
coord: ['伊兰特CNG', 8.6]
}],
[{
coord: ['B50汽油', 0]
}, {
coord: ['B50汽油', 9.3]
}],
[{
coord: ['凯美瑞混合动力', 0]
}, {
coord: ['凯美瑞混合动力', 7.5] //平行于Y轴的 虚线
}]
],
},
},
{
name: '预警值',
type: 'line',
color: '#333',
symbol: 'triangle', //起点标记图形 (三角形),详细请见 http://echarts.baidu.com/option.html#series-line.markLine.data.0.symbol
itemStyle: {
normal: {
borderWidth: 1,
lineStyle: {
type: 'dash',
color: 'transparent ',
width: 2,
},
label: {
formatter: '',
textStyle: {
color: '#333',
fontSize: 16,
fontWeight: "bolder",
},
}
},
},
data: data1.map(function (val) {
return val;
}),
label: {
normal: {
show: true,
formatter: function (params) {
return params.value; //预警值 对应显示 data1 预警值
}
}
}
}
],
};
//判断数值动态设置颜色
$(document).ready(function (params) {
for (var i = 0; i < seriesData.length; i++) {
if (seriesData[i].value) {
seriesData[i] = seriesData[i].value;
}
if (seriesData[0] > 10.2) {
seriesData[0] = {
value: seriesData[0],
itemStyle: {
normal: {
color: '#c23531'
}
}
}
} else if (seriesData[0] <= 10.2) {
seriesData[0] = {
value: seriesData[0],
itemStyle: {
normal: {
color: '#c5bf66'
}
}
}
} if (seriesData[1] > 8.6) {
seriesData[1] = {
value: seriesData[1],
itemStyle: {
normal: {
color: '#c23531'
}
}
}
} else if (seriesData[1] <= 8.6) {
seriesData[1] = {
value: seriesData[1],
itemStyle: {
normal: {
color: '#c5bf66'
}
}
}
} if (seriesData[2] > 9.3) {
seriesData[2] = {
value: seriesData[2],
itemStyle: {
normal: {
color: '#c23531'
}
}
}
} else if (seriesData[2] <= 9.3) {
seriesData[2] = {
value: seriesData[2],
itemStyle: {
normal: {
color: '#c5bf66'
}
}
}
} if (seriesData[3] > 7.5) {
seriesData[3] = {
value: seriesData[3],
itemStyle: {
normal: {
color: '#c23531'
}
}
}
} else if (seriesData[3] <= 7.5) {
seriesData[3] = {
value: seriesData[3],
itemStyle: {
normal: {
color: '#c5bf66'
}
}
}
}
}
// console.log(seriesData);
// option1.series[0].data=seriesData
myChart1.setOption(option1, true);
})
myChart1.setOption(option1);
var myChart2 = echarts.init(document.getElementById('main2'));
option2 = {
title: {
text: '分车龄能耗预警'
},
color: ['#F8CB00'],
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
right: '6%',
bottom: '3%',
containLabel: true
},
xAxis: [{
type: 'category',
data: ['1年', '2年', '3年', '4年', '5年', '6年', '7年', '8年'],
axisTick: {
alignWithLabel: true
}
}],
yAxis: [{
type: 'value',
name: '百公里能耗L/100KM',
min: 0,
max: 15,
interval: 3,
axisLabel: {
formatter: '{value}'
}
}],
series: [{
name: '',
type: 'bar',
barWidth: '65%',
data: [8.1, 13.3, 1.5, 14.6, 10.8, 9.0, 9.2, 9.3],
markLine: { //开始标预警线
itemStyle: {
normal: {
borderWidth: 1,
lineStyle: {
type: 'dash',
color: '#333 ',
width: 2,
},
label: {
formatter: '12.6',
textStyle: {
fontSize: 16,
fontWeight: "bolder",
},
}
},
emphasis: {
borderColor: '#1e90ff',
borderWidth: 5,
label: {
show: true,
formatter: 'hhh'
}
},
},
data: [
[{
coord: ['1年', 12.6]
}, {
coord: ['8年', 12.6]
}]
],
},
itemStyle: {
normal: {
color: function (params) { //根据预警线的值 显示对应的颜色
// build a color map as your need.
var colorList = ['#c23531', '#c5bf66 '];
if (params.data > 12.6) {
return colorList[0];
} else if (params.data < 12.6) {
return colorList[1];
}
}
},
}
}],
};
myChart2.setOption(option2);
</script>
</body>
</html>