-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.html
190 lines (176 loc) · 6.29 KB
/
main.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>疫情地图展示</title>
<style>
.container {
width: 1200px;
margin: 0 auto;
}
#myEcharts {
width: 1000px;
height: 800px;
margin: 0 auto;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.js"></script>
<!-- 引入 echarts.js -->
<script src="https://cdn.jsdelivr.net/npm/echarts@4/dist/echarts.min.js?_v_=1611323308745"></script>
<!--引入中国的地图数据js文件,引入后会自动注册地图名字和数据-->
<script src="https://cdn.jsdelivr.net/npm/echarts@4/map/js/china.js?_v_=1611323308745"></script>
</head>
<body>
<div class="container">
<!--为echarts准备一个dom容器-->
<div id="myEcharts"></div>
</div>
<script>
const mp = new Map([
['安徽', 'Anhui'],
['北京', 'Beijing'],
['福建', 'Fujian'],
['甘肃', 'Gansu'],
['广东', 'Guangdong'],
['广西', 'Guangxi'],
['贵州', 'Guizhou'],
['海南', 'Hainan'],
['河北', 'Hebei'],
['河南', 'Henan'],
['黑龙江', 'Heilongjiang'],
['湖北', 'Hubei'],
['湖南', 'Hunan'],
['吉林', 'Jilin'],
['江苏', 'Jiangsu'],
['江西', 'Jiangxi'],
['辽宁', 'Liaoning'],
['内蒙古', 'Inner Mongolia'],
['宁夏', 'Ningxia'],
['青海', 'Qinghai'],
['山东', 'Shandong'],
['山西', 'Shanxi'],
['陕西', 'Shaanxi'],
['上海', 'Shanghai'],
['四川', 'Sichuan'],
['天津', 'Tianjin'],
['西藏', 'Tibet'],
['新疆', 'Xinjiang'],
['云南', 'Yunnan'],
['浙江', 'Zhejiang'],
['重庆', 'Chongqing'],
['香港', 'HongKong'],
['澳门', 'Macao'],
['台湾', 'Taiwan'],
['南海诸岛', 'South China Sea Islands']
]);
//初始化echarts实例
var myChart = echarts.init(document.getElementById('myEcharts'));
// 指定图表的配置项和数据
option = {
title: {
text: 'China Covid Map',
left: 'center',
textStyle: {
fontSize: 30,
},
},
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left',
data: ['China Covid Map']
},
visualMap: {
type: 'piecewise',
pieces: [
{ min: 1000, max: 1000000, label: 'over 1000', color: '#372a28' },
{ min: 500, max: 999, label: '500-999', color: '#4e160f' },
{ min: 100, max: 499, label: '100-499', color: '#974236' },
{ min: 10, max: 99, label: '10-99', color: '#ee7263' },
{ min: 1, max: 9, label: '1-9', color: '#f5bba7' },
],
color: ['#E0022B', '#E09107', '#A3E00B']
},
// toolbox: {
// show: true,
// orient: 'vertical',
// left: 'right',
// top: 'center',
// feature: {
// mark: { show: true },
// dataView: { show: true, readOnly: false },
// restore: { show: true },
// saveAsImage: { show: true }
// }
// },
roamController: {
show: true,
left: 'right',
mapTypeControl: {
'china': true
}
},
series: [
{
name: 'Comfirmed',
type: 'map',
mapType: 'china',
roam: false,
data: [],
}
]
};
//使用指定的配置项和数据显示图表
myChart.setOption(option);
//获取数据
function getData() {
$.ajax({
url: "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5",
dataType: "jsonp",
success: function (data) {
// console.log(data.data)
var res = data.data || "";
res = JSON.parse(res);
var newArr = [];
if (res) {
//获取到各个省份的数据
var province = res.areaTree[0].children;
for (var i = 0; i < province.length; i++) {
var json = {
name: mp.get(province[i].name),
value: province[i].total.nowConfirm
}
newArr.push(json)
}
console.log(newArr)
console.log(JSON.stringify(newArr))
//使用指定的配置项和数据显示图表
myChart.setOption({
series: [
{
name: 'Comfirmed',
type: 'map',
mapType: 'china',
roam: false,
label: {
show: true,
color: 'black',
// fontWeight: 'bold',
// fontSize: 14,
},
data: newArr,
nameMap: Object.fromEntries(mp),
}
]
});
}
}
})
}
getData();
</script>
</body>
</html>