码迷,mamicode.com
首页 > 其他好文 > 详细

Echarts data赋值

时间:2018-06-12 11:22:59      阅读:1603      评论:0      收藏:0      [点我收藏+]

标签:配置   tst   scroll   .ajax   UNC   i++   document   success   color   

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赋值

标签:配置   tst   scroll   .ajax   UNC   i++   document   success   color   

原文地址:https://www.cnblogs.com/panyw/p/9172093.html

(0)
(3)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!