美好的一天,
我有这样的JSON数据,
const incidents = [
{
"id": 3,
"fullName": "Fatima Elaran",
"address": "San Marcos, Calumpit, Bulacan",
},
{
"id": 4,
"fullName": "Leni Elaran",
"address": "San Marcos, Calumpit, Bulacan",
}
]
我按地址汇总总数,方法如下:
const count = incidents.reduce((a, c) => {
a[c.address] = (a[c.address] || 0) + 1;
return a;
}, {});
将count
设置为:
{ San Marcos, Calumpit, Bulacan: 2 }
现在,我更新我的图表以显示此汇总数据:
Object.keys(count).forEach(key => {
this.barChart.labels.push(key);
});
Object.values(count).forEach(data => {
this.barChart.data.push(data);
});
但barChart.data
以此数据结尾:[2, "San Marcos, Calumpit, Bulacan"]
我希望它只有这个:["San Marcos, Calumpit, Bulacan"]