<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/echart/echarts.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/echart/esl.js"></script>
<script type="text/javascript" src="js/echart/echarts.min.js"></script>
function getEcharts2(data){
var geoCoordMap = {
'绥化': [126.968887,46.653845],
'哈尔滨': [126.534967,45.803775],
'佳木斯': [130.306119,46.799608],
'鹤岗': [130.284147,47.34582],
'双鸭山': [131.135587,46.675373],
'伊春': [128.844938,47.735185],
'大庆': [125.104093,46.59994],
'齐齐哈尔': [123.912076,47.360706],
'长春': [125.285367,43.841975],
'牡丹江': [129.613981,44.558693],
'大连': [121.593961,38.907619],
'海拉尔区': [119.736279,49.212189]
};
var GZData = [
[{ name: '哈尔滨' }, { name: '绥化', value: 95 }],
[{ name: '哈尔滨' }, { name: '佳木斯', value: 90 }],
[{ name: '哈尔滨' }, { name: '鹤岗', value: 80 }],
[{ name: '哈尔滨' }, { name: '伊春', value: 70 }],
[{ name: '哈尔滨' }, { name: '双鸭山', value: 60 }],
[{ name: '哈尔滨' }, { name: '大庆', value: 50 }],
[{ name: '哈尔滨' }, { name: '齐齐哈尔', value: 40 }],
[{ name: '哈尔滨' }, { name: '长春', value: 20 }],
[{ name: '哈尔滨' }, { name: '牡丹江', value: 10 }],
[{ name: '哈尔滨' }, { name: '大连', value: 25 }],
[{ name: '哈尔滨' }, { name: '海拉尔区', value: 25 }]
];
var seriesMap = [['哈尔滨', GZData]];
//初始化数据
// var geoCoordMap = data.result.geoCoordMap;
//
// var seriesMap = data.result.seriesMap;
var convertData = function (data) {
var res = [];
for (var i = 0; i < data.length; i++) {
var dataItem = data[i];
var fromCoord = geoCoordMap[dataItem[0].name];
var toCoord = geoCoordMap[dataItem[1].name];
if (fromCoord && toCoord) {
//cnt定义数量,这里面随意增加自定义属性
res.push({
fromName: dataItem[0].name,
toName: dataItem[1].name,
cnt:dataItem[1].value,
coords: [fromCoord, toCoord]
})
}
}
return res;
};
//初始化series
var color = ['#a6c84c', '#ffa022', '#46bee9'];
var series = [];
seriesMap.forEach(function (item, i) {
series.push({
name: item[0],
type: 'lines',
zlevel: 1,
effect: {
show: true,
period: 6,
trailLength: 0,
symbol: 'triangle',// 箭头方式:'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'
symbolSize: 20,
// loop: false
},
tooltip : {
formatter:function (params, ticket, callback) {
//鼠标悬浮提示信息获取自定义的结果
var htm = `<div><span>出发地:${params.data.fromName}</span>
<br><span>目的地:${params.data.toName}</span>
<br><span>订单量:${params.data.cnt}</span>
</div>`;
return htm;
}
},
lineStyle: {
normal: {
color: color[i],
width: 1,
opacity: 0.4,
curveness: 0.2
}
},
data: convertData(item[1])
},
{
name: item[0] ,
type: 'effectScatter',
coordinateSystem: 'geo',
zlevel: 2,
rippleEffect: {
brushType: 'stroke'
},
tooltip : {
formatter:function (params, ticket, callback) {
return params.data.name;
}
},
label: {
normal: {
show: true,
position: 'right',
formatter: '{b}'
}
},
symbolSize: function (val) {
return 16;
},
itemStyle: {
normal: {
color: color[i]
}
},
data: item[1].map(function (dataItem) {
return {
name: dataItem[1].name,
value: geoCoordMap[dataItem[1].name].concat([dataItem[1].value])
};
})
});
});
var option = {
backgroundColor: '#404a59',
title: {
text: '旅游巴士迁徙图',
left: 'center',
textStyle: {
color: '#fff'
}
},
tooltip : {
trigger: 'item'
},
legend: {
orient: 'vertical',
top: 'bottom',
left: 'right',
data:[''],
textStyle: {
color: '#fff'
},
selectedMode: 'single'
},
geo: {
map: 'china',
// center: [108.114129, 28.550339],
center: [126.522926,45.75821],
label: {
normal: {
show: true,
formatter: '{a}',
// position: 'inside',
backgroundColor: '#fff',
padding: [3, 5],
borderRadius: 3,
borderWidth: 1,
borderColor: 'rgba(0,0,0,0.5)',
color: '#777'
},
emphasis: {
}
},
selectedMode: 'single',
roam: true,
itemStyle: {
normal: {
areaColor: '#323c48',
borderColor: '#404a59'
},
emphasis: {
areaColor: '#2a333d'
}
}
},
series: series
}
$.get('js/echart/map/china.json', function (chinaJson) {
echarts.registerMap('china', chinaJson);
var chart = echarts.init(document.getElementById('mainMap'));
chart.setOption(option);
});
}
function getEcharts3(data){
// 为模块加载器配置echarts的路径,从当前页面链接到echarts.js,定义所需图表路径
require.config({
paths: {
echarts: '/echart'
}
});
require([
'echarts/echarts'
], function (echarts) {
// var geoCoordMap = {
// '绥化': [126.968887,46.653845],
// '哈尔滨': [126.534967,45.803775],
// '佳木斯': [130.306119,46.799608],
// '鹤岗': [130.284147,47.34582],
// '双鸭山': [131.135587,46.675373],
// '伊春': [128.844938,47.735185],
// '大庆': [125.104093,46.59994],
// '齐齐哈尔': [123.912076,47.360706],
// '长春': [125.285367,43.841975],
// '牡丹江': [129.613981,44.558693],
// '大连': [121.593961,38.907619],
// '海拉尔区': [119.736279,49.212189]
// };
// var GZData = [
// [{ name: '哈尔滨' }, { name: '绥化', value: 95 }],
// [{ name: '哈尔滨' }, { name: '佳木斯', value: 90 }],
// [{ name: '哈尔滨' }, { name: '鹤岗', value: 80 }],
// [{ name: '哈尔滨' }, { name: '伊春', value: 70 }],
// [{ name: '哈尔滨' }, { name: '双鸭山', value: 60 }],
// [{ name: '哈尔滨' }, { name: '大庆', value: 50 }],
// [{ name: '哈尔滨' }, { name: '齐齐哈尔', value: 40 }],
// [{ name: '哈尔滨' }, { name: '长春', value: 20 }],
// [{ name: '哈尔滨' }, { name: '牡丹江', value: 10 }],
// [{ name: '哈尔滨' }, { name: '大连', value: 25 }],
// [{ name: '哈尔滨' }, { name: '海拉尔区', value: 25 }]
// ];
// var seriesMap = [['哈尔滨', GZData]];
var geoCoordMap = data.result.geoCoordMap;
var seriesMap = data.result.seriesMap;
var convertData = function (data) {
var res = [];
for (var i = 0; i < data.length; i++) {
var dataItem = data[i];
var fromCoord = geoCoordMap[dataItem[0].name];
var toCoord = geoCoordMap[dataItem[1].name];
if (fromCoord && toCoord) {
//cnt定义数量,这里面随意增加自定义属性
res.push({
fromName: dataItem[0].name,
toName: dataItem[1].name,
cnt:dataItem[1].value,
coords: [fromCoord, toCoord]
})
}
}
return res;
};
$.get('js/echart/map/china.json', function (chinaJson) {
// $.get('https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json', function (chinaJson) {
echarts.registerMap('china', chinaJson);
var myChart = echarts.init(document.getElementById('mainMap'));
var color = ['#a6c84c', '#ffa022', '#46bee9'];
var series = [];
seriesMap.forEach(function (item, i) {
series.push(
{
name: item[0],
type: 'lines',
zlevel: 1,
effect: {
show: true,
period: 6,
trailLength: 0,
symbol: 'triangle',// 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'
symbolSize: 20,
// loop: false
},
tooltip : {
formatter:function (params, ticket, callback) {
//鼠标悬浮提示信息获取自定义的结果
var htm = `<div><span>出发地:${params.data.fromName}</span>
<br><span>目的地:${params.data.toName}</span>
<br><span>订单量:${params.data.cnt}</span>
</div>`;
return htm;
}
},
lineStyle: {
normal: {
color: color[i],
width: 1,
opacity: 0.4,
curveness: 0.2
}
},
data: convertData(item[1])
},
{
name: item[0] ,
type: 'effectScatter',
coordinateSystem: 'geo',
zlevel: 2,
rippleEffect: {
brushType: 'stroke'
},
tooltip : {
formatter:function (params, ticket, callback) {
return params.data.name;
}
},
label: {
normal: {
show: true,
position: 'right',
formatter: '{b}'
}
},
symbolSize: function (val) {
return 16;
},
itemStyle: {
normal: {
color: color[i]
}
},
data: item[1].map(function (dataItem) {
return {
name: dataItem[1].name,
value: geoCoordMap[dataItem[1].name].concat([dataItem[1].value])
};
})
});
});
myChart.setOption({
backgroundColor: '#404a59',
title: {
text: '旅游巴士迁徙图',
left: 'center',
textStyle: {
color: '#fff'
}
},
tooltip : {
trigger: 'item'
},
legend: {
orient: 'vertical',
top: 'bottom',
left: 'right',
data:[''],
textStyle: {
color: '#fff'
},
selectedMode: 'single'
},
geo: {
map: 'china',
// center: [108.114129, 28.550339],
center: [126.522926,45.75821],
label: {
normal: {
show: true,
formatter: '{a}',
// position: 'inside',
backgroundColor: '#fff',
padding: [3, 5],
borderRadius: 3,
borderWidth: 1,
borderColor: 'rgba(0,0,0,0.5)',
color: '#777'
},
emphasis: {
}
},
selectedMode: 'single',
roam: true,
itemStyle: {
normal: {
areaColor: '#323c48',
borderColor: '#404a59'
},
emphasis: {
areaColor: '#2a333d'
}
}
},
series: series
});
});
});
}