//餅圖模板
var dom = document.getElementById("first");
var myChart = echarts.init(dom);
var app = {};
option = null;
option = {
title : {
text: '用戶位置記錄',
subtext: '',
x:'center'
},
tooltip : {
trigger: 'item',
formatter: "{a} br/> : {c} (yyieoyi%)"
},
legend: {
orient : 'vertical',
x : 'left',
data:[]
},
toolbox: {
show : true,
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false},
magicType : {
show: true,
type: ['pie', 'funnel'],
option: {
funnel: {
x: '25%',
width: '50%',
funnelAlign: 'left',
max: 1548
}
}
},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
series : [
{
name:'',
type:'pie',
radius : '55%',
center: ['50%', '60%'],
data:[]
}
]
};
;
if (option typeof option === "object") {
myChart.setOption(option, true);
}
//餅圖動態(tài)賦值
var year = $("#year-search").val();
var mouth = $("#mouth-search").val();
$.ajax({
type: "get",
url: rootPath+"/wxbound/getPieDataByMouth.action",
data : {"year":year,"mouth":mouth},
cache : false, //禁用緩存
dataType: "json",
success: function(result) {
var names=[];//定義兩個數(shù)組
var nums=[];
$.each(result,function(key,values){ //此處我返回的是listString,mapString,String>>循環(huán)map
names.push(values.province_name);
var obj = new Object();
obj.name = values.province_name;
obj.value = values.count;
nums.push(obj);
});
myChart.setOption({ //加載數(shù)據(jù)圖表
legend: {
data: names
},
series: {
// 根據(jù)名字對應到相應的系列
name: ['數(shù)量'],
data: nums
}
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("查詢失敗");
}
});
//柱形圖模板
var domLong = document.getElementById("second");
var myChartSecond = echarts.init(domLong);
var app = {};
option = null;
option = {
color: ['#3398DB'],
tooltip : {
trigger: 'axis',
axisPointer : { // 坐標軸指示器,坐標軸觸發(fā)有效
type : 'shadow' // 默認為直線,可選為:'line' | 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis : [
{
type : 'category',
data : [],
axisTick: {
alignWithLabel: true
}
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
name:'直接訪問',
type:'bar',
barWidth: '60%',
data:[]
}
]
};
if (option typeof option === "object") {
myChartSecond.setOption(option, true);
}
//給柱形圖賦值
var year = $("#year-search").val();
$.ajax({
type: "post",
url: rootPath+"/wxbound/getWxboundList.action",
data : {"year":year},
cache : false, //禁用緩存
dataType: "json",
success: function(result) {
console.log(result);
var linNames=[];
var linNums=[];
$.each(result.lin,function(key,values){
linNames.push(values.mouth);
linNums.push(values.count);
});
//柱形圖賦值
myChartSecond.setOption({ //加載數(shù)據(jù)圖表
xAxis: {
data: linNames
},
series: {
// 根據(jù)名字對應到相應的系列
name: ['數(shù)量'],
data: linNums
}
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("查詢失敗");
}
});
}
以上這篇ajax動態(tài)賦值echarts的實例(餅圖和柱形圖)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。