效果图
代码
<!-- 引入 ECharts 文件 -->
<script src="../js/echarts-4.1.0/echarts.js"></script>
<script src="../js/theme/customed.js"></script>
<script src="../js/map/js/china.js"></script>
<script type="text/javascript">
// 构建echarts图表所需的数据
var app={};
var data = [
{name: '地点1', value: 200,text:'发生事件1'},
{name: '地点2', value: 200,text:'发生事件2'},
{name: '地点3', value: 200,text:'发生事件3'},
{name: '地点4', value: 200,text:'发生事件4'},
{name: '地点5', value: 200,text:'发生事件5'},
{name: '地点6', value: 200,text:'发生事件6'},
{name: '地点7', value: 200,text:'发生事件7'},
{name: '地点8', value: 200,text:'发生事件8'},
];
var geoCoordMap = {
'地点1':[116.41,42.99],
'地点2':[119.3,26.08],
'地点3':[108.95,34.27],
'地点4':[87.68,41.77],
'地点5':[104.06,32.67],
'地点6':[116.60,40.08],
'地点7':[111.56,29.86],
'地点8':[120.19,30.26]
};
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].text)
//geoCoord.concat(data[i].value).concat(data[i].text)
});
}
}
return res;
};
option = {
title: {
text: '自定义地图',
x:'center',
top:30,
textStyle:{
color: '#46c898',
fontSize:25
}
},
tooltip : {
trigger: 'item',
triggerOn: 'mousemove|click',//移动或者点击
formatter: function (params) {
for (var i = 0; i < option.series[0].data.length; i++) {
if (option.series[0].data[i].name == params.data.name) {
var text = option.series[0].data[i].value;
return params.data.name +" "+ text[2];
}
}
}
},
geo: {
map: 'china',
roam : true,
label: {
emphasis: {
show: false
}
},
zoom:1.2,
// layoutCenter : ['50%', '47.5%'],
itemStyle: {
normal: {
areaColor: '#688d80',//rgba(128, 128, 128, 0.1)
borderColor: '#111'
},
emphasis: {
areaColor: '#7ca99c'
}
}
},
series : [
{
type: 'scatter',
coordinateSystem: 'geo',
data: convertData(data),
},
{
//name: 'Top 5',
type: 'effectScatter',
coordinateSystem: 'geo',
data: convertData(data.sort(function (a, b) {
return b.value - a.value;
}).slice(0, 10)),
// symbolSize: function (val) {
// return val[2] / 10;
// },
symbolSize: 15,
hoverAnimation: true,
label: {
formatter: ' {b}',
position: 'right',
// color : "#d96809",
show: true
},
itemStyle: {
normal: {
color: '#f4e925',
shadowBlur: 20,
shadowColor: '#333'
}
},
showEffectOn: 'render',
rippleEffect: {
brushType: 'stroke'
}
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
app.currentIndex = -1;
setInterval(function () {
var dataLen = option.series[0].data.length;
// 取消之前高亮的图形
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 1,
dataIndex: app.currentIndex
});
app.currentIndex = (app.currentIndex + 1) % dataLen;
// 高亮当前图形
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 1,
dataIndex: app.currentIndex
});
// 显示 tooltip
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 1,
dataIndex: app.currentIndex
});
}, 3000);
//点击事件
// myChart.on('click', function (params) {
// });
</script>
工作中使用到的,总结归纳后,仅供各位大神们参考......