function groupByKey(list, key) {
console.log(list);
let tmpKeyList = list.map(o => o[key]);
let keyList = [...new Set(tmpKeyList)];
console.log(keyList); //一共有多少种分类
let result = [];
keyList.map(o => {
let data = [];
for (let i = 0, len = list.length; i < len; i++) {
if (list[i][key] == o) {
data.push(list[i].CNT);
}
}
result.push({
name: o,
data
});
});
console.log(result);
}
let list = [{
APP_ID: "APP001",
CNT: 0,
STAT_DATE: "06-20"
}, {
APP_ID: "APP002",
CNT: 0,
STAT_DATE: "06-20"
}, {
APP_ID: "APP001",
CNT: 0,
STAT_DATE: "06-21"
}, {
APP_ID: "APP002",
CNT: 0,
STAT_DATE: "06-21"
}];
groupByKey(list, 'APP_ID');