准备工作:导入ECharts依赖、和地图需要的.js文件。
文件获取方式:
官网:url
github:url
(下载完后 :incubator-echarts-4.8.0\map\js\province目录下有各个省级的.js文件)
绘制中国地图
先在html中添加一个地图要挂载的节点:china-map
js:
var myChart = echarts.init(document.getElementById('china-map'));
var option = {
tooltip: {
// show: false //不显示提示标签
formatter: '{b}', //提示标签格式
backgroundColor:"#ff7f50",//提示标签背景颜色
textStyle:{color:"#fff"} //提示标签字体颜色
},
series: [{
type: 'map',
mapType: 'china',
label: {
normal: {
show: true,//显示省份标签
textStyle:{color:"#c71585"}//省份标签字体颜色
},
emphasis: {//对应的鼠标悬浮效果
show: true,
textStyle:{color:"#800080"}
}