Echarts data赋值
Posted panyw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Echarts data赋值相关的知识,希望对你有一定的参考价值。
1.
var date=new Date;
var countYear = eval(‘${countForYear}‘);
var countYear1=0;
for (var i = 0; i < countYear.length; i++) {
if(date.getFullYear() == countYear[i].yearNo){
countYear1 = countYear[i].count;
}
}
// echarts设置
// 基于准备好的dom,初始化echarts实例
var yearStatistics = echarts.init(document.getElementById(‘yearStatistics‘));
// 指定图表的配置项和数据
var optionYear = {
title: [{
text: ‘公司各年度投诉反馈情况‘,
left: ‘center‘,
textStyle:{ //设置主标题风格
color:‘green‘
}
},{
subtext: ‘年度投诉反馈:‘,
left: ‘left‘
}],
tooltip: {},
xAxis: {
text:‘11‘,
data: date.getFullYear()-5
},
yAxis: {},
series: [{
name: ‘年份‘,
type: ‘line‘,
data: countYear1
}]
};
yearStatistics.setOption(optionYear);
}
2. 通过ajax获取数据并赋值
var countDept = "";
var dept = [];
var deptContent = [];
$.ajax({
url:‘URL‘,
type:‘post‘,
data:{
nowTime:yearForDept
},
dataType : "json",
success :function(data){
if(data.result == 1){
countDept = eval(data.countForDept);
// 先清空数组
dept.splice(0,dept.length);
deptContent.splice(0,deptContent.length);
for (var i = 0; i < countDept.length; i++) {
dept.push(countDept[i].handlerDept);
deptContent.push({
name:countDept[i].handlerDept,
value:countDept[i].count
})
}
initPieEcharts();
}else{
showErrMsg(yearForDept+"年,查无数据");
return;
}
}
});
function initPieEcharts(){
。。。。。。
legend: {
type: ‘scroll‘,
right: 10,
top: 30,
bottom: 20,
data: dept
},
series : [
{
name:‘投诉反馈比例‘,
type: ‘pie‘,
radius : ‘55%‘,
center: [‘50%‘, ‘50%‘],
selectedMode: ‘single‘,
data: deptContent,
}
]
。。。。。。
}
以上是关于Echarts data赋值的主要内容,如果未能解决你的问题,请参考以下文章