First ECharts Map(苏州)
🏷️ ECharts
主要参考了 ECharts Gallery 示例 及 ECharts 配置项手册。
点击查看页面代码
html
<script src="/dist/libs/echarts/4.3.0/echarts.min.js"></script><style>
.echart {
max-width: 750px;
height: 900px;
padding: 10px 0;
}
@media (max-width: 750px) {
.echart {
width: 100%;
height: 600px;
}
}
</style>
<div id="ncov-suzhou-area" class="echart"></div>
<script>
$(function() {
var suzhou = '/dist/libs/geo/suzhou.geo.json';
var mapName = 'suzhou';
$.get(suzhou, function(szJson) {
echarts.registerMap(mapName, szJson);
var geoCoordMap = {};
var sz_data = [
{name: '', value: 10},
{name: '吴中区', value: 9},
{name: '相城区', value: 8},
{name: '姑苏区', value: 7},
{name: '工业园区', value: 6},
{name: '高新区', value: 5},
{name: '吴江区', value: 4},
{name: '常熟市', value: 3},
{name: '张家港市', value: 2},
{name: '昆山市', value: 1},
{name: '太仓市', value: 1}
];
var goTotal=0;//计算总人数
sz_data.forEach(function(item,i){
goTotal+=item.value;
})
window.echart_area = echarts.init(document.getElementById('ncov-suzhou-area'));
window.echart_area.showLoading();
var mapFeatures = echarts.getMap(mapName).geoJson.features;
window.echart_area.hideLoading();
mapFeatures.forEach(function(v) {
// 地区名称
var name = v.properties.name;
// 地区经纬度
geoCoordMap[name] = v.properties.centroid;
});
var convertData = function(data) {
var res = [];
for (var i = 0; i < data.length; i++) {
var geoCoord = geoCoordMap[data[i].name];
if (geoCoord) {
res.push({
name: data[i].name,
value: geoCoord.concat(data[i].value),
});
}
}
return res;
};
option = {
visualMap: {
show: true,
min: 0,
max: 10,
left: 'left',
top: 'bottom',
text: ['高', '低'], // 文本,默认为数值文本
calculable: true,
seriesIndex: [1],
inRange: {
color: ['#fff', '#ff6384'],
}
},
//地图相关设置
geo: {
map: mapName,
zoom: 1.2,
roam: false,
normal: {
label: {
color: '#F62157',
show: false
},
itemStyle: {
color: '#F62157',
areaColor: '#fff',
borderColor: '#e64c6c',
}
},
emphasis: {
label: {
color: '#fff',
show: false
},
itemStyle: {
color: '#fff',
areaColor: '#fb4f73',
borderColor: '#fff',
}
},
},
series: [
{
name: '散点',
type: 'scatter',
coordinateSystem: 'geo',
data: convertData(sz_data),
symbolSize: 1,
label: {
normal: {
formatter: '{b}',
position: 'right',
show: true,
fontSize: 12
},
emphasis: {
show: true,
}
},
itemStyle: {
normal: {
color: '#000'
}
}
},
{
type: 'map',
map: mapName,
geoIndex: 0,
aspectScale: 0.75, //长宽比
showLegendSymbol: false, // 存在 legend 时显示
label: {
normal: {
show: true
},
emphasis: {
show: false,
textStyle: {
color: '#fff'
}
}
},
roam: true,
itemStyle: {
normal: {
areaColor: '#037be3',
borderColor: '#0089ff',
},
emphasis: {
areaColor: '#037be3'
}
},
animation: false,
data: sz_data
},
{
name: '点',
type: 'scatter',
coordinateSystem: 'geo',
symbol: 'pin', //气泡
symbolSize: 50,
label: {
normal: {
show: true,
formatter: '{@[2]}',
textStyle: {
color: '#fff',
fontSize: 9,
}
}
},
itemStyle: {
normal: {
color: '#F62157', //标志颜色
}
},
zlevel: 6,
data: convertData(sz_data),
}]
};
window.echart_area.setOption(option);
});
});
</script>
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
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