1、npm i echarts --save
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts
2、下载省级地图json(下载地址)
3、当前页面引入JSON
import chongqing from "./assets/chongqing.json"
4、使用
<template>
<div id="mychart" style="width: 900px;height: 900px;"></div>
</template>
mounted() {
this.$nextTick(()=>{
this.mychart = this.$echarts.init(document.getElementById("mychart"));
this.$echarts.registerMap("chosenMap", chongqing );
let option = {
backgroundColor: "#404a59",
title: {
text: "重庆",
top: 25,
left: "center",
textStyle: {
fontSize: 25,
fontWeight: 650,
color: "#fff",
},
},
tooltip: {
trigger: "item",
formatter: function(val) {
return "人数: 人";
},
},
toolbox: {
show: true,
orient: "vertical",
left: "right",
top: "center",
feature: {
dataView: {
readOnly: false
},
restore: {},
saveAsImage: {},
},
},
series: [{
name: '重庆',
type: "map",
mapType: "chosenMap",
label: {
show: true,
},
itemStyle: {
normal: {
areaColor: "#323c48",
borderColor: "#111",
label: {
show: true,
color: "white",
},
},
emphasis: {
areaColor: "#2a333d",
label: {
show: true,
color: "white",
},
},
},
roam: true,
top: 70,
label: {
show: true,
},
data: [{
name: "江津区",
itemStyle: {
color: '#0489d6',
areaColor: "blue",
opacity: 1,
borderWidth: 0.4,
borderColor: 'red'
},
label: {
show: true,
textStyle: {
color: '#fff',
}
},
}]
}, ],
};
this.mychart.on("click", function(params) {
console.log(params);
});
this.mychart.setOption(option);
})
},
5、3D地图配置
- 下载echarts-gl :npm i echarts-gl --save
- 当前页面引入
import “echarts-gl”
- 参数配置
series: [
{
type: 'map3D',
name: '重庆',
selectedMode:"single",
boxDepth:90,
regionHeight:8,
map: '重庆',
viewControl:{
distance:150,
rotateSensitivity:0,
zoomSensitivity:0,
}
}]