echerts動態載入資料
阿新 • • 發佈:2019-01-26
option = {
title: {
text: '某站點使用者訪問來源',
subtext: '純屬虛構',
x: 'center'
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
legend: {
orient: 'vertical' ,
left: 'left',
data: ['直接訪問', '郵件營銷', '聯盟廣告', '視訊廣告', '搜尋引擎']
},
series: [
{
name: '訪問來源',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: [
],
itemStyle: {
emphasis: {
shadowBlur: 10 ,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
function fuzhi(myChart){
$.ajax({
contentType : "application/json",
type : "GET" ,
url : "${pageContext.request.contextPath}/ht/ea",
datatype:'json',
success : function(data) {
alert(data);
//建立一個數組,用來裝物件傳給series.data,因為series.data裡面不能直接鞋for迴圈
var sa=[];
sa=['直接訪問', '郵件營銷', '聯盟廣告', '視訊廣告', '搜尋引擎'];
myChart.setOption({
title:{
text: '某站點使用者訪問來源',
subtext: '純屬虛構'
},
legend: {
orient: 'vertical',
left: 'left',
data: sa
},
series:[
{
name: '訪問來源',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: data
}
]
});
}
});
}
//初始化echarts例項
var myChart = echarts.init(document.getElementById('chartmain'));
fuzhi(myChart);
//使用制定的配置項和資料顯示圖表
myChart.setOption(option);