效果如下

1,安装echarts

1
npm install echarts --save

2,引入

1
2
import echarts from "echarts";       
import 'echarts/map/js/china.js' //引入中国地图数据 (*********重中之重)

3,配制option

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
{

visualMap: { //地图图例
show:true,
left: 26,
bottom: 40,
showLabel:true,
pieces: [ //根据数据大小,各省显示不同颜色
{
gte: 100,
label: ">= 1000",
color: "#1f307b"
},
{
gte: 500,
lt: 999,
label: "500 - 999",
color: "#3c57ce"
},
{
gte: 100,
lt:499,
label: "100 - 499",
color: "#6f83db"
},
{
gte: 10,
lt: 99,
label: "10 - 99",
color: "#9face7"
},
{
lt:10,
label:'<10',
color: "#bcc5ee"
}
]
},
geo: { //中国地图设置
map: "china",
scaleLimit: {
min: 1,
max: 2
},
zoom: 1,
top: 120,
label: {
normal: {
show:true,
fontSize: "14",
color: "rgba(0,0,0,0.7)"
}
},
itemStyle: {
normal: {
borderColor: "rgba(0, 0, 0, 0.2)"
},
emphasis: {
areaColor: "#f2d5ad",
shadowOffsetX: 0,
shadowOffsetY: 0,
borderWidth: 0
}
}
},
series: [
{
name: "突发事件",
type: "map",
geoIndex: 0,
data:[]
}
]
}

Vue地图组件—源码如下(引入调用即可使用)

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
<template>
<div id="china_map_box">
<div id="china_map"></div>
</div>
</template>

<script>
import echarts from "echarts";
import 'echarts/map/js/china.js'
export default {
data() {
return {
//echart 配制option
options: {
tooltip: {
triggerOn: "mousemove", //mousemove、click
padding:8,
borderWidth:1,
borderColor:'#409eff',
backgroundColor:'rgba(255,255,255,0.7)',
textStyle:{
color:'#000000',
fontSize:13
},
formatter: function(e, t, n) {
let data = e.data;
//模拟数据
data.specialImportant = Math.random()*1000 | 0;
data.import = Math.random()*1000 | 0;
data.compare = Math.random()*1000 | 0;
data.common = Math.random()*1000 | 0;
data.specail = Math.random()*1000 | 0;

let context = `
<div>
<p><b style="font-size:15px;">${data.name}</b>(2020年第一季度)</p>
<p class="tooltip_style"><span class="tooltip_left">事件总数</span><span class="tooltip_right">${data.value}</span></p>
<p class="tooltip_style"><span class="tooltip_left">特别重大事件</span><span class="tooltip_right">${data.specialImportant}</span></p>
<p class="tooltip_style"><span class="tooltip_left">重大事件</span><span class="tooltip_right">${data.import}</span></p>
<p class="tooltip_style"><span class="tooltip_left">较大事件</span><span class="tooltip_right">${data.compare}</span></p>
<p class="tooltip_style"><span class="tooltip_left">一般事件</span><span class="tooltip_right">${data.common}</span></p>
<p class="tooltip_style"><span class="tooltip_left">特写事件</span><span class="tooltip_right">${data.specail}</span></p>
</div>
`
return context;
}
},
visualMap: {
show:true,
left: 26,
bottom: 40,
showLabel:true,
pieces: [
{
gte: 100,
label: ">= 1000",
color: "#1f307b"
},
{
gte: 500,
lt: 999,
label: "500 - 999",
color: "#3c57ce"
},
{
gte: 100,
lt:499,
label: "100 - 499",
color: "#6f83db"
},
{
gte: 10,
lt: 99,
label: "10 - 99",
color: "#9face7"
},
{
lt:10,
label:'<10',
color: "#bcc5ee"
}
]
},
geo: {
map: "china",
scaleLimit: {
min: 1,
max: 2
},
zoom: 1,
top: 120,
label: {
normal: {
show:true,
fontSize: "14",
color: "rgba(0,0,0,0.7)"
}
},
itemStyle: {
normal: {
//shadowBlur: 50,
//shadowColor: 'rgba(0, 0, 0, 0.2)',
borderColor: "rgba(0, 0, 0, 0.2)"
},
emphasis: {
areaColor: "#f2d5ad",
shadowOffsetX: 0,
shadowOffsetY: 0,
borderWidth: 0
}
}
},
series: [
{
name: "突发事件",
type: "map",
geoIndex: 0,
data:[]
}
]
},
//echart data
dataList: [
{
name: "南海诸岛",
value: 100,
eventTotal:100,
specialImportant:10,
import:10,
compare:10,
common:40,
specail:20
},
{
name: "北京",
value: 540
},
{
name: "天津",
value: 130
},
{
name: "上海",
value: 400
},
{
name: "重庆",
value: 750
},
{
name: "河北",
value: 130
},
{
name: "河南",
value: 830
},
{
name: "云南",
value: 110
},
{
name: "辽宁",
value: 19
},
{
name: "黑龙江",
value: 150
},
{
name: "湖南",
value: 690
},
{
name: "安徽",
value: 60
},
{
name: "山东",
value: 39
},
{
name: "新疆",
value: 4
},
{
name: "江苏",
value: 31
},
{
name: "浙江",
value: 104
},
{
name: "江西",
value: 36
},
{
name: "湖北",
value: 52
},
{
name: "广西",
value: 33
},
{
name: "甘肃",
value: 7
},
{
name: "山西",
value: 5
},
{
name: "内蒙古",
value: 778
},
{
name: "陕西",
value: 22
},
{
name: "吉林",
value: 4
},
{
name: "福建",
value: 18
},
{
name: "贵州",
value: 5
},
{
name: "广东",
value: 98
},
{
name: "青海",
value: 1
},
{
name: "西藏",
value: 0
},
{
name: "四川",
value: 44
},
{
name: "宁夏",
value: 4
},
{
name: "海南",
value: 22
},
{
name: "台湾",
value: 3
},
{
name: "香港",
value: 5
},
{
name: "澳门",
value: 555
}
]
};
},
methods: {
//初始化中国地图
initEchartMap() {
let mapDiv = document.getElementById('china_map');
let myChart = echarts.init(mapDiv);
myChart.setOption(this.options);
},
//修改echart配制
setEchartOption(){
this.options.series[0]['data'] = this.dataList;
}
},
created() {
this.setEchartOption();
},
mounted() {
this.$nextTick(()=>{
this.initEchartMap();
})

}
};
</script>

<style scoped>
#china_map_box {
height: 100%;
position: relative;
}
#china_map_box #china_map{
height: 100%;
}
#china_map_box .china_map_logo{
position: absolute;
top: 0;
left: 0;
width:45px;
}
</style>
<style>
#china_map .tooltip_style{
line-height:1.7;
overflow: hidden;
}
#china_map .tooltip_left{
float: left;
}
#china_map .tooltip_right{
float: right;
}

</style>