在data外做一个循环,然后用这个数组替换data
var data = [];
方法一:
for (var i =0;i<depts.length;i++){
data.push({
value:depts[i],
name:deptsname[i]
})
}
方法二:
for (var i =0;i<depts.length;i++){
data[i]={};
data[i].value=depts[i];
data[i].name=deptsname[i];
}
console.log(data);
var optionRecords2 = {
title: {
text: '部门人数统计',
subtext: '部门/人数',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 10,
data: [depts,deptsname]
},
series: [
{
name: '访问来源',
type: 'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: false,
label: {
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: '30',
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
data : data
}
]
};
echartsRecords2.setOption(optionRecords2);