roleArr=[
{type: "bar", barWidth: 5, name: "name1", data: 206}
{type: "bar", barWidth: 5, name: "name2", data: 198}
{type: "bar", barWidth: 5, name: "name3", data: 165}
{type: "bar", barWidth: 5, name: "name1", data: 149}
{type: "bar", barWidth: 5, name: "name2", data: 132}
{type: "bar", barWidth: 5, name: "name3", data: 121}
{type: "bar", barWidth: 5, name: "name1", data: 119}
{type: "bar", barWidth: 5, name: "name2", data: 92}
]
let newArr = [];
let tempArr = [];
//根据name属性整合数据
for (let i = 0; i < roleArr.length; i++) {
if (tempArr.indexOf(roleArr[i].name) === -1) {
newArr.push({
type: roleArr[i].type,
barWidth: roleArr[i].barWidth,
name: roleArr[i].name,
data: [roleArr[i].data]
});
tempArr.push(roleArr[i].name);
} else {
for (let j = 0; j < newArr.length; j++) {
if (newArr[j].name == roleArr[i].name) {
newArr[j].data.push(roleArr[i].data);
}
}
}
}