效果图
需要导入以下文件
<script src="~/Scripts/jquery.js"></script>/*Jquery文件*/
<script src="~/Scripts/echarts.js"></script>/*echarts文件,可从官网下载*/
<script src="~/Scripts/jiangxi.js"></script>/*省份数据,可从我的网盘中下载*/
以下是完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
<div id="echartMap" style="width: 1000px;height:1000px;"></div>
<script src="jquery.min.js"></script>
<script src="echarts.min.js"></script>
<script src="jiangxi.js"></script>
<script type="text/javascript">
var sData=[
{name:'南昌市',value:12000000},
{name:'上饶市',value:12000000},
{name:'景德镇市',value:12000000},
{name:'九江市',value:12000000},
{name:'宜春市',value:12000000},
{name:'抚州市',value:12000000},
{name:'吉安市',value:12000000},
{name:'赣州市',value:12000000},
{name:'新余市',value:12000000},
{name:'萍乡市',value:12000000},
{name:'鹰潭市',value:12000000},
]
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('echartMap'));
var option = {
tooltip: {
show: true,
trigger: 'item',
triggerOn: 'click',
formatter: "名称:{b}<br />坐标:{c}"
},
series: [{
name: "江西省分布",
type: 'custom',//配置显示方式为用户自定义
legendHoverLink:true,
coordinateSystem: 'geo',
// itemStyle: {
// normal: {
// color: '#46bee9'
// },
// label:{show:true}
// },
data: sData // coldCar
}
],
legend: {
// type: "plain",
show: true,
orient: 'vertical',
x: 'middle',
y: 'left',
data: [
{
name: "分布",
icon: "circle",
textStyle: {
color: "#a9d6fa"
}
}
]
},
geo: {//引入江西省的地图
map: '江西',
label: {
show:true,
color:'#000',
fontSize:18,
emphasis: {
show: true,
color:'#000',
}
},
roam: true,
zoom: 1,
zlevel:0,
itemStyle: {
normal: {
borderColor: '#fff'
},
emphasis: {
borderColor: '#1890ff',
shadowColor: 'rgba(0, 0, 0, 0.5)',
shadowBlur: 5,
shadowOffsetX: 5
}
},
regions: [//对不同的区块进行着色
{
name: '上饶市',
itemStyle: {
normal: {
areaColor: '#5CD89E'
},
emphasis: {
areaColor: '#5CD89E',
}
}
}, {
name: '景德镇市',
itemStyle: {
normal: {
areaColor: '#FCCF73'
},
emphasis: {
areaColor: '#FCCF73',
}
}
}, {
name: '鹰潭市',
itemStyle: {
normal: {
areaColor: '#81A1FD'
},
emphasis: {
areaColor: '#81A1FD',
}
}
}, {
name: '南昌市',
itemStyle: {
normal: {
areaColor: '#FD898D'
},
emphasis: {
areaColor: '#FD898D',
}
}
}, {
name: '九江市',
itemStyle: {
normal: {
areaColor: '#FCCF73'
},
emphasis: {
areaColor: '#FCCF73',
}
}
}, {
name: '宜春市',
itemStyle: {
normal: {
areaColor: '#81A1FD'
},
emphasis: {
areaColor: '#81A1FD',
}
}
}, {
name: '抚州市',
itemStyle: {
normal: {
areaColor: '#FCCF73'
},
emphasis: {
areaColor: '#FCCF73',
}
}
}, {
name: '新余市',
itemStyle: {
normal: {
areaColor: '#5CD89E'
},
emphasis: {
areaColor: '#5CD89E',
}
}
}, {
name: '萍乡市',
itemStyle: {
normal: {
areaColor: '#FCCF73'
},
emphasis: {
areaColor: '#FCCF73',
}
}
}, {
name: '吉安市',
itemStyle: {
normal: {
areaColor: '#FD898B'
},
emphasis: {
areaColor: '#FD898B',
}
}
}, {
name: '赣州市',
itemStyle: {
normal: {
areaColor: '#81A1FD'
},
emphasis: {
areaColor: '#81A1FD',
}
}
}
]
}
};
myChart.setOption(option);
myChart.on('click',function(params){
if(params.componentType=='geo'){
if(params.name='上饶市'){
console.log('上饶市');
}
}
})
</script>
</body>
</html>
注:关于文字不居中,地图上显示名称的位置为其省会的坐标位置。在导入的地图数据中,直接搜索相关地区名字,可以看到经纬度坐标。也就是只需要改变cp下的经纬度就可以改变图上文字位置。