大資料視覺化--全球分佈散點圖
阿新 • • 發佈:2019-01-08
//返回隨機顏色
function getColor() {
var colors = ['#00F5FF','#00E5EE','#00FFFF','#00C5CD'];
var index = Math.floor((Math.random() * colors.length));
return colors[index];
}
require([
'echarts'
// 'echarts/chart/map',
// 'echarts/chart/scatter',
// 'echarts/component/legend',
// 'echarts/component/geo',
// 'echarts/component/visualMap'
], function (echarts) {
$.get('../map/json/world.json', function (worldJson) {
echarts.registerMap('world' , worldJson);
var latlong = [
{'latitude':42.5, 'longitude':1.5},
{'latitude':22, 'longitude':116},
{'latitude':24, 'longitude':54},
{'latitude':24, 'longitude':54},
{'latitude':33 , 'longitude':65},
{'latitude':17.05, 'longitude':-61.8},
{'latitude':18.25, 'longitude':-63.1667}];
var chart = echarts.init(document.getElementById('main'), null, {
});
var max = -Infinity;
var min = Infinity;
console.profile('setOption');
chart.setOption({
title : {
x:'center',
y:'top'
},
tooltip : {
trigger: 'item',
formatter : function (params) {
return '';
}
},
visualMap: {
show: false,
min: 0,
max: max,
inRange: {
symbolSize: [20, 20]
}
},
geo: {
name: '',
//型別
type: 'map',
//地圖
map: 'world',
roam: true,
z:1,
//圖形上的文字標籤,這裡不顯示
label: {
emphasis: {
show: false
}
},
//地圖區域的多邊形 圖形樣式
itemStyle: {
//普通狀態
normal: {
areaColor: '#000',
borderColor: '#1C86EE'
},
//高亮狀態
emphasis: {
color: 'rgba(0,191,255, 0.2)'
}
}
},
series : [
{
type: 'effectScatter',
coordinateSystem: 'geo',
//可以容納的動畫數量
animationThreshold:50000,
//是否啟用圖例 hover 時的聯動高亮。
legendHoverLink:true,
//特效型別,目前只支援漣漪特效'ripple'
effectType:'ripple',
//配置何時顯示特效,render表示渲染完就顯示
showEffectOn:'render',
//漣漪特效相關配置,period:動畫的時間,scale:動畫中波紋的最大縮放比例,brushType:波紋的繪製方式,可選 'stroke' 和 'fill'
rippleEffect:{'period':5, 'scale':3, 'brushType':'stroke'},
symbolSize:[2,10],
symbolRotate :10,
data: latlong.map(function (itemOpt) {
return {
value: [
itemOpt.longitude,
itemOpt.latitude
],
label: {
emphasis: {
show: false
}
},
itemStyle: {
normal: {
//color: getColor(),
// 徑向漸變,前三個引數分別是圓心 x, y 和半徑,取值同線性漸變
color: {
type: 'radial',
x: 2,
y: 2,
r: 1,
colorStops: [{
offset: 0, color: getColor() // 0% 處的顏色
}, {
offset: 1, color: getColor() // 100% 處的顏色
}],
globalCoord: false // 預設為 false
}
}
},
z:2,
};
})
}
]
});
console.profileEnd('setOption');
});
});