【发布时间】:2020-01-03 12:15:44
【问题描述】:
我正在尝试在使用 highcharts (https://api.highcharts.com/highcharts/) 的 react js 中构建一个饼图,它只接受以下饼图数据格式(或者我错了):Sample Fiddle here:https://jsfiddle.net/react_user1/e9cbsrdL/1/
data: [
{name: 'abc', y: 10},
{name: 'def', y: 90}
]
我从 API 获得的数据如下所示:
const counts:[
{
"id": "all",
"type": "all",
"count": 1403
},
{
"id": "bad",
"type": "bad",
"count": 0
},
{
"id": "failed",
"category": false,
"type": "failed",
"count": 58
},
{
"id": "changed",
"category": true,
"type": "changed",
"count": 123
}
所以我在这里尝试实现三件事:
1. Remove the first {}, with the "id": "all"
2. Rename the key: "id" to name & "count" to y
3. Remove the keys: "type" & "category" & their data
感谢您提供的任何帮助,即使是可以提供帮助的部分答案也将不胜感激。
【问题讨论】:
标签: javascript arrays reactjs charts highcharts