配置项如下
var chart = echarts.init(document.getElementById('main'));
var cityProper = {
'城阳区': 'js/chengyang.json',
'崂山区': 'js/laoshan.json',
'李沧区': 'js/licang.json',
'市北区': 'js/shibei.json',
'市南区': 'js/shinan.json',
'胶南': 'js/jiaonan.json',
'胶州': 'js/jiaozhou.json',
'即墨': 'js/jimo.json',
'莱西': 'js/laixi.json',
'平度': 'js/pingdu.json'
};
var data = [{
name: '城阳区'
}, {
name: '崂山区'
}, {
name: '李沧区'
}, {
name: '市北区'
}, {
name: '市南区'
}, {
name: '胶南'
}, {
name: '胶州'
}, {
name: '即墨'
}, {
name: '莱西'
}, {
name: '平度'
}];
for (var i = 0; i < data.length; i++) {
data[i].value = Math.round(Math.random() * 10000);
}
option = {
tooltip: {
trigger: 'item'
},
toolbox: {
show: true,
orient: 'vertical',
x: 'right',
y: 'center',
feature: {
mark: {
show: true
},
dataView: {
show: true,
readOnly: false
}
}
},
series: [{
tooltip: {
trigger: 'item'
},
name: '选择器',
type: 'map',
mapType: 'qingdao',
mapLocation: {
x: 'left',
y: 'top',
width: '30%'
},
roam: true,
selectedMode: 'single',
itemStyle: {
normal: {
label: {
show: true
}
},
emphasis: {
label: {
show: true
}
}
},
data: data
}],
animation: false
};
chart.setOption(option, true);
//var ecConfig = echarts.config;
chart.on("click", function(param) {
var selected = param.selected;
//console.log(option.series[0].data[1].selected);
var selectedProvince = param.name;
if (!cityProper[selectedProvince]) {
option.series.splice(1);
option.legend = null;
option.visualMap = null;
chart.setOption(option, true);
return;
}
$.get(cityProper[selectedProvince], function(geojson) {
echarts.registerMap(selectedProvince, geojson);
option.series[1] = {
name: '选择器',
type: 'map',
mapType: selectedProvince,
left: '50%',
top: 'top',
width: '30%',
roam: true,
selectedMode: 'single',
itemStyle: {
normal: {
label: {
show: true
}
},
emphasis: {
label: {
show: true
}
}
},
data: data
};
option.legend = {
left: 'right',
data: ['随机数据']
};
option.visualMap = {
seriesIndex: 1,
orient: 'horizontal',
left: 'right',
min: 0,
max: 1000,
color: ['orange', 'yellow'],
text: ['高', '低'], // 文本,默认为数值文本
splitNumber: 0
};
chart.setOption(option, true);
})
});