-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.js
477 lines (446 loc) · 12.6 KB
/
ajax.js
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/**
*向腾讯发送请求,获取实时数据
*
*/
var data, other;
function getData() {
$.ajax({
url: 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5',
dataType: "jsonp",
success: function(res) {
data = JSON.parse(res.data);
center1();
center2();
right1();
right2();
}
})
$.ajax({
url: 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_other',
dataType: 'jsonp',
success: function (result) {
other = JSON.parse(result.data);
left1();
left2();
}
});
}
getData()
function center1() {
document.getElementById('confirm').innerText = data.chinaTotal.confirm;
document.getElementById('heal').innerText = data.chinaTotal.heal;
document.getElementById('dead').innerText = data.chinaTotal.dead;
document.getElementById('nowConfirm').innerText = data.chinaTotal.nowConfirm;
document.getElementById('noInfect').innerText = data.chinaTotal.noInfect;
document.getElementById('import').innerText = data.chinaTotal.importedCase;
}
function center2() {
var center2Chart = echarts.init(document.getElementById('center2'), 'dark');
var option = {
title: {
text: '',
},
tooltip: {
trigger: 'item'
},
visualMap: { // 左侧小导航图标
show: true,
x: 'left',
y: 'bottom',
textStyle: {
fontSize: 8,
},
splitList: [{
start: 1,
end: 9
},
{
start: 10,
end: 99
},
{
start: 100,
end: 999
},
{
start: 1000,
end: 9999
},
{
start: 10000
}
],
color: ['#8A3310', '#C64918', '#E55B25', '#F2AD92', '#F9DCD1']
},
series: [{
name: '累计确诊人数',
type: 'map',
mapType: 'china',
roam: false, // 禁用拖动和缩放
itemStyle: { // 图形样式
normal: {
borderWidth: .5, //区域边框宽度
borderColor: '#009fe8', //区域边框颜色
areaColor: '#ffefd5', //区域颜色
},
emphasis: { // 鼠标滑过地图高亮的相关设置
borderWidth: .5,
borderColor: '#4b0082',
areaColor: '#fff',
}
},
label: { // 图形上的文本标签
normal: {
show: true, //省份名称
fontSize: 8,
},
emphasis: {
show: true,
fontSize: 8,
}
},
data: [] // [{'name': '上海', 'value': 318}, {'name': '云南', 'value': 162}]
}]
};
var provinces = data.areaTree[0].children;
for (var province of provinces) {
option.series[0].data.push({
'name': province.name,
'value': province.total.confirm
});
}
center2Chart.setOption(option);
}
function left1() {
var left1Chart = echarts.init(document.getElementById('left1'), 'dark');
var option = {
title: {
text: '全国累计趋势',
textStyle: {
color: 'white',
},
left: 'left',
},
tooltip: {
trigger: 'axis',
//指示器
axisPointer: {
type: 'line',
lineStyle: {
color: '#7171C6'
}
},
},
//图例
legend: {
data: ['累计确诊', '累计治愈', '累计死亡'],
left: 'right'
},
//图形位置
grid: {
left: '4%',
right: '6%',
bottom: '4%',
top: 50,
containLabel: true
},
xAxis: [{
type: 'category',
data: [] // ['03.20', '03.21', '03.22']
}],
yAxis: [{
type: 'value',
//y轴字体设置
axisLabel: {
show: true,
color: 'white',
fontSize: 12,
formatter: function (value) {
if (value >= 1000) {
value = value / 1000 + 'k';
}
return value;
}
},
//y轴线设置显示
axisLine: {
show: true
},
//与x轴平行的线样式
splitLine: {
show: true,
lineStyle: {
color: '#17273B',
width: 1,
type: 'solid',
}
}
}],
series: [{
name: '累计确诊',
type: 'line',
smooth: true,
data: [] // [20, 406, 529]
}, {
name: '累计治愈',
type: 'line',
smooth: true,
data: [] // [25, 75, 122]
}, {
name: '累计死亡',
type: 'line',
smooth: true,
data: [] // [6, 15, 47]
}]
};
var chinaDayList = other.chinaDayList;
for (var day of chinaDayList) {
option.xAxis[0].data.push(day.date);
option.series[0].data.push(day.confirm);
option.series[1].data.push(day.heal);
option.series[2].data.push(day.dead);
}
left1Chart.setOption(option);
}
function left2() {
var left2Chart = echarts.init(document.getElementById('left2'), 'dark');
var option = {
title: {
text: '全国新增趋势',
textStyle: {
color: 'white',
},
left: 'left',
},
tooltip: {
trigger: 'axis',
//指示器
axisPointer: {
type: 'line',
lineStyle: {
color: '#7171C6'
}
},
},
//图例
legend: {
data: ['新增确诊', '新增疑似'],
left: 'right'
},
//图形位置
grid: {
left: '4%',
right: '6%',
bottom: '4%',
top: 50,
containLabel: true
},
xAxis: [{
type: 'category',
data: [] // ['03.20', '03.21', '03.22']
}],
yAxis: [{
type: 'value',
//y轴字体设置
axisLabel: {
show: true,
color: 'white',
fontSize: 12,
formatter: function (value) {
if (value >= 1000) {
value = value / 1000 + 'k';
}
return value;
}
},
//y轴线设置显示
axisLine: {
show: true
},
//与x轴平行的线样式
splitLine: {
show: true,
lineStyle: {
color: '#17273B',
width: 1,
type: 'solid',
}
}
}],
series: [{
name: '新增确诊',
type: 'line',
smooth: true,
data: [] // [20, 406, 529]
}, {
name: '新增疑似',
type: 'line',
smooth: true,
data: [] // [25, 75, 122]
}]
};
var chinaDayAddList = other.chinaDayAddList;
for (var day of chinaDayAddList) {
option.xAxis[0].data.push(day.date);
option.series[0].data.push(day.confirm);
option.series[1].data.push(day.suspect);
}
left2Chart.setOption(option);
}
function right1() {
var right1Chart = echarts.init(document.getElementById('right1'), 'dark');
var option = {
title: {
text: '全国确诊省市TOP10',
textStyle: {
color: 'white',
},
left: 'left'
},
color: ['#3398DB'],
tooltip: {
trigger: 'axis',
//指示器
axisPointer: {
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
xAxis: {
type: 'category',
data: [] // ['湖北','广州','北京']
},
yAxis: {
type: 'value',
//y轴字体设置
axisLabel: {
show: true,
color: 'white',
fontSize: 12,
formatter: function (value) {
if (value >= 1000) {
value = value / 1000 + 'k';
}
return value;
}
},
},
series: [{
data: [], // [582, 300, 100]
type: 'bar',
barMaxWidth: '50%'
}]
};
var provinces = data.areaTree[0].children;
var topData = [];
for (var province of provinces) {
topData.push({
'name': province.name,
'value': province.total.confirm
});
}
// 降序排列
topData.sort(function (a, b) {
return b.value - a.value;
});
// 只保留前10条
topData.length = 10;
// 分别取出省份名称和数据
for (var province of topData) {
option.xAxis.data.push(province.name);
option.series[0].data.push(province.value);
}
right1Chart.setOption(option);
}
function right2() {
var right2Chart = echarts.init(document.getElementById('right2'), 'dark');
var option = {
title: {
text: '境外输入省市TOP5',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
data: [] // ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
},
series: [{
name: '省市名称',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
// data: [
// {value: 335, name: '直接访问'},
// {value: 310, name: '邮件营销'},
// {value: 234, name: '联盟广告'},
// {value: 135, name: '视频广告'},
// {value: 1548, name: '搜索引擎'}
// ],
data: [],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}]
};
var provinces = data.areaTree[0].children;
var topData = [];
for (var province of provinces) {
if (province.children[0].name == '境外输入') {
topData.push({
'name': province.name,
'value': province.children[0].total.confirm
});
}
}
// 降序排列
topData.sort(function (a, b) {
return b.value - a.value;
});
// 只保留前5条
topData.length = 5;
// 分别取出省份名称和数据
for (var province of topData) {
option.legend.data.push(province.name);
option.series[0].data.push(province);
}
right2Chart.setOption(option);
}
// 每5分钟自动获取数据
setInterval(getData,5*60*1000);
/**
* 实时显示时间
*/
function showTime() {
//获取年月日时分秒
var time = new Date();
var year = time.getFullYear();
var month = check(time.getMonth()+1); // 检查是否需要补0
var day = check(time.getDate());
var hour = check(time.getHours());
var minute = check(time.getMinutes());
var second = check(time.getSeconds());
var content = year + '年' + month + '月' + day + '日 ' + hour + ':' + minute + ':' + second;
if($('#title span').length==0){
$('#title').append($('<span>').text(content).css({
position:'absolute',
left:'20px',
fontSize:'20px'
}));
}else{
$('#title span').text(content);
}
}
showTime();
// 检查数字,如果是个位数,则补0
function check(num) {
return num < 10 ? '0' + num : num;
}
// 每1秒刷新时间
setInterval(showTime,1000);