通过ajax获得数据后,如果是**异步**获取数据
必须将echarts的定义写成方法
function initEcharts(){
var dom = document.getElementById("productionPlan-echarts");
var myChart = echarts.init(dom);
option = {
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
series: [
{
name:'生产计划',
type:'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: false,
label: {
normal: {
show: false,
position: 'center'
},
emphasis: {
show: false,
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
data:eData //eData是一个json数组
}
]
};
myChart.setOption(option,true);
}
然后将这个方法放入ajax中最后的地方,不然json数组可能无法获取数据