-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
380 lines (372 loc) · 12.4 KB
/
index.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<title>毕业数据可视化</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/app.css" />
</head>
<body class="bg01">
<header class="header">
<h3>毕业数据可视化</h3>
</header>
<div class="wrapper">
<div class="container-fluid">
<div class="row fill-h">
<div class="col-lg-3 fill-h">
<div class="xpanel-wrapper xpanel-wrapper-2">
<div class="xpanel">
<!-- 地图飞线 -->
<div class="fill-h" id="flyMap"></div>
</div>
</div>
</div>
<div class="col-lg-6 fill-h">
<div class="xpanel-wrapper xpanel-wrapper-1">
<div class="xpanel">
<!-- 地图散点 -->
<div class="fill-h" id="scatterMap"></div>
</div>
</div>
</div>
<div class="col-lg-3 fill-h">
<div class="xpanel-wrapper xpanel-wrapper-3">
<div class="xpanel">
<!-- 省份地图 -->
<div class="fill-h" id="provinceMap"></div>
</div>
</div>
<div class="xpanel-wrapper xpanel-wrapper-3">
<div class="xpanel">
<!-- 城市地图 -->
<div class="fill-h" id="cityMap"></div>
</div>
</div>
<div class="xpanel-wrapper xpanel-wrapper-3">
<div class="xpanel">
<!-- 区县地图 -->
<div class="fill-h" id="countyMap"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="js/echarts-3.8.5.min.js"></script>
<script type="text/javascript" src="js/echarts-map-world.js"></script>
<script type="text/javascript" src="js/echarts-map-china.js"></script>
<script type="text/javascript" src="js/echarts-china-provinces/jiangsu.js"></script>
<script type="text/javascript" src="js/echarts-china-cities/jiang1_su1_su1_zhou1.js"></script>
<script type="text/javascript" src="js/echarts-china-counties/jiang1su1_su1zhou1_kun1shan1shi4.js"></script>
<script type="text/javascript">
$(function() {
/******************* 地图飞线 ******************/
//初始化echarts实例
const flyMap = echarts.init(document.getElementById("flyMap"));
//城市经纬度
const originName = '衡水';
const flyGeo = {
'衡水':[115.68, 37.74],'北京':[116.33, 40.01],'上海':[121.47, 31.24],'广州':[113.27, 23.13],
};
//飞线数据
var flyVal = [
[{name:'衡水'}, {name:'衡水', value:100}],[{name:'北京'}, {name:'衡水', value:3}],[{name:'上海'}, {name:'衡水', value:1}],[{name:'广州'}, {name:'衡水', value:1}],
];
//数据转换,转换后格式:[{fromName:'cityName', toName:'cityName', coords:[[lng, lat], [lng, lat]]}, {...}]
const convertFlyData = function(data) {
let res = [];
for(let i=0;i<data.length;i++) {
let dataItem = data[i];
let toCoord = flyGeo[dataItem[0].name];
let fromCoord = flyGeo[dataItem[1].name];
if(fromCoord && toCoord) {
res.push({
fromName: dataItem[1].name,
toName: dataItem[0].name,
coords: [fromCoord, toCoord]
});
}
}
return res;
};
//报表配置
const flySeries = [];
[[originName, flyVal]].forEach(function(item, i) {
flySeries.push({
name: item[0],
type: 'lines',
zlevel: 1,
symbol: ['none', 'none'],
symbolSize: 0,
effect: { //特效线配置
show: true,
period: 5, //特效动画时间,单位s
trailLength: 0.1, //特效尾迹的长度,从0到1
symbol: 'arrow',
symbolSize: 5
},
lineStyle: {
normal: {
color: '#f19000',
width: 1,
opacity: 0.6,
curveness: 0.2 //线的平滑度
}
},
data: convertFlyData(item[1])
}, {
name: item[0],
type: 'effectScatter',
coordinateSystem: 'geo',
zlevel: 2,
rippleEffect: { //涟漪特效
period: 5, //特效动画时长
scale: 4, //波纹的最大缩放比例
brushType: 'stroke' //波纹的绘制方式:stroke | fill
},
label: {
normal: {
show: false,
position: 'right',
formatter: '{b}'
}
},
symbol: 'circle',
symbolSize: function (val) {
//根据某项数据值设置符号大小
return val[2] / 10;
},
itemStyle: {
normal: {
color: '#f19000'
}
},
data: item[1].map(function(dataItem) {
return {
name: dataItem[1].name,
value: flyGeo[dataItem[1].name].concat([dataItem[1].value])
};
})
}, { //与上层的点叠加
name: item[0],
type: 'scatter',
coordinateSystem: 'geo',
zlevel: 3,
symbol: 'circle',
symbolSize: function (val) {
//根据某项数据值设置符号大小
return val[2] / 15;
},
itemStyle: {
normal: {
color: '#f00'
}
},
data: item[1].map(function(dataItem) {
return {
name: dataItem[1].name,
value: flyGeo[dataItem[1].name].concat([dataItem[1].value])
};
})
});
});
//报表配置项
const flyMapOpt = {
title: {
show: false,
text: '地图飞线',
x: 'center',
textStyle: {
color: '#fff'
}
},
tooltip: {
trigger: 'item',
formatter: function(params) {
if(params.value) {
return params.name + ' : ' + params.value[2];
}else {
return params.name;
}
}
},
geo: {
map: 'china',
roam: false, //开启鼠标缩放和漫游
zoom: 1, //地图缩放级别
selectedMode: false, //选中模式:single | multiple
left: 0,
right: 0,
top: 0,
bottom: 0,
layoutCenter: ['50%', '50%'], //设置后left/right/top/bottom等属性无效
layoutSize: '100%', //保持地图宽高比
label: {
emphasis: {
show: false
}
},
itemStyle: {
normal: {
areaColor: '#101f32',
borderWidth: 1.1,
borderColor: '#43d0d6'
},
emphasis: {
areaColor: '#069'
}
}
},
series: flySeries
};
//渲染报表
flyMap.setOption(flyMapOpt);
/***************** 地图散点 ******************/
//初始化echarts实例
const scatterMap = echarts.init(document.getElementById("scatterMap"));
//城市经纬度
const scatterGeo = {
"北京理工大学":[116.32, 39.95],"某某大学":[118.18, 39.64],"某某某大学":[121.47, 31.24],"某大学":[121.47, 31.24],
};
//城市数据
const scatterVal = [
{name:"北京理工大学", value:"一咕,二咕,三咕"},{name:"某某大学", value:"四咕"},{name:"某某某大学", value:"五五咕"},{name:"某大学", value:"六咕"},
];
//数据转换,转换后的格式:[{name: 'cityName', value: [lng, lat, val]}, {...}]
const convertScatterData = function(data) {
let res = [];
for(let i=0;i<data.length;i++) {
let geoCoord = scatterGeo[data[i].name];
if(geoCoord) {
res.push({
name: data[i].name,
value: geoCoord.concat(data[i].value)
});
}
}
return res;
};
//地图配置项
const sactterMapOpt = {
title: {
text: '各学校分布图',
x: 'center',
textStyle: {
color: '#fff'
}
},
legend: {
data: ['各校名单'], //与series的name属性对应
orient: 'vertical',
y: 'bottom',
x: 'right',
textStyle: {
color: '#fff'
}
},
tooltip: {
trigger: 'item',
formatter: function(params) {
return params.name + ' : ' + params.value[2];
}
},
geo: {
map: 'china',
roam: false, //开启鼠标缩放和漫游
zoom: 1, //地图缩放级别
selectedMode: false, //选中模式:single | multiple
left: 0,
right: 0,
top: 0,
bottom: 0,
layoutCenter: ['50%', '50%'], //设置后left/right/top/bottom等属性无效
layoutSize: '100%',
label: {
emphasis: {
show: false
}
},
itemStyle: {
normal: {
areaColor: '#101f32',
borderWidth: 1.1,
borderColor: '#43d0d6'
},
emphasis: {
areaColor: '#069'
}
}
},
series: [{
name: 'PM2.5',
type: 'scatter',
coordinateSystem: 'geo',
symbolSize: 12,
label: {
normal: {
show: false
},
emphasis: {
show: false
}
},
itemStyle: {
emphasis: {
borderColor: '#fff',
borderWidth: 1
}
},
data: convertScatterData(scatterVal)
}]
};
//渲染报表
scatterMap.setOption(sactterMapOpt);
/******************* 世界地图 ******************/
//初始化echarts实例
const worldMap = echarts.init(document.getElementById("worldMap"));
const worldMapOpt = {
geo: {
map: 'world',
roam: false, //开启鼠标缩放和漫游
zoom: 1, //地图缩放级别
selectedMode: false, //选中模式:single | multiple
left: 0,
right: 0,
top: 0,
bottom: 0,
layoutCenter: ['50%', '50%'], //设置后left/right/top/bottom等属性无效
layoutSize: '100%',
label: {
emphasis: {
show: false
}
},
itemStyle: {
normal: {
areaColor: '#101f32',
borderWidth: 1.1,
borderColor: '#43d0d6'
},
emphasis: {
areaColor: '#069'
}
}
}
};
worldMap.setOption(worldMapOpt);
/********** 浏览器窗口改变时,重置报表大小 ****************/
window.onresize = function() {
flyMap.resize();
scatterMap.resize();
worldMap.resize();
provinceMap.resize();
cityMap.resize();
countyMap.resize();
}
});
</script>
</body>
</html>