调取ajax接口获取饼图所需的data数组,控制台报错如图:
代码如下:
$.ajax({
url:"../driverAnalysis.do?method=getDriverAnalysisData",
async:false,
type: "POST",
dataType: 'JSON',
data: {},
success: function (data) {
if(data.status==0){
var myChart8 = echarts.init(document.getElementById('zjcxtj'));
var option8 = {
title:{
text:"驾驶员准驾车型统计",
top:'10',
left:'30',
//x: '30',
textStyle: {//主标题文本样式{"fontSize": 18,"fontWeight": "bolder","color": "#333
color:'#fff'
},
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
/*legend: {
orient: 'vertical',
right:'120',
top:'65',
textStyle:{//图例文字的样式
color:'#fff',
fontSize:14
},
data:['A1','A2','A3','B1','B2','C1','C2','C3','C4','其他']
},*/
//color:['#fffd55', '#c1ff85','#2eee9a','#85ffe7','#d5a8ff','#996af8','#7032ee','#3248ee','#ee2e60','#ee9332'],
series: [
{
name:'准驾车型统计',
type:'pie',
center: ['30%', '55%'],
radius: ['50%', '70%'],
avoidLabelOverlap: false,
//文字在环形内的定位
label: {
normal: {
show: false,
position: 'center'
},
emphasis: {
show: true,
textStyle: {
fontSize: '20',
fontWeight: 'bold'
}
}
},
//改成true 就会显示细条
labelLine: {
normal: {
show: true,
x:"right"
}
},
data:data.data.zjcxtj
}
]
};
myChart8.setOption(option8);
}
}
})
试了很久不知道问题出在哪里,把data.data.zjcxtj打印出来然后把打印出来的数组静态插入就没问题
配置项什么的都对,解析后台数据时传过来的是一个字符串,应该在前面加上一个JSON.parse()