大家好,我想询问一些关于从对象数组创建新对象数组的问题。我需要修改数据,因为我需要在React Native中使用Victory库创建分组条形图。当前的数据需要进行调整以创建图表。
数据看起来像这样:
[
{
"date": "April 2022",
"phase": [
{
"phaseName": "initiation",
"days": 7
},
{
"phaseName": "justification",
"days": 6
},
{
"phaseName": "planning",
"days": 4
}
]
},
{
"date": "Mei 2022",
"phase": [
{
"phaseName": "justification",
"days": 44
},
{
"phaseName": "partner-selection",
"days": 32
},
{
"phaseName": "planning",
"days": 40
},
{
"phaseName": "initiation",
"days": 25
},
{
"phaseName": "signing",
"days": 5
}
]
},
{
"date": "Juni 2022",
"phase": [
{
"phaseName": "signing",
"days": 6
},
{
"phaseName": "planning",
"days": 54
},
{
"phaseName": "justification",
"days": 36
},
{
"phaseName": "initiation",
"days": 28
},
{
"phaseName": "partner-selection",
"days": 30
}
]
}
]
我该如何创建类似这样的数据?(Victory能够接受的数据)
[
{
x:'April 2022',
y: 7,
type: 'initiation'
},
{
x: 'Mei 2022',
y: 44,
type: 'justification'
},
{
x: 'Juni 2022',
y: 6,
type: 'signing'
}
],
[
{
x: 'April 2022',
y: 6,
type: 'justification'
},
{
x: 'Mei 2022',
y: 32,
type: 'partner-selection'
},
{
x: 'Juni 2022',
y: 54,
type: 'planning'
}
],
[
{
x: 'April 2022',
y: 4,
type: 'planning'
},
{
x: 'Mei 2022',
y: 40,
type: 'planning'
},
{
x: 'Juni 2022',
y: 36,
type: 'justification'
}
],
[
{
x: 'Mei 2022',
y: 25,
type: 'initiation'
},
{
x: 'Juni 2022',
y: 28,
type: 'initiation'
}
],
[
{
x: 'Mei 2022',
y: 5,
type: 'signing'
},
{
x: 'Juni',
y: 30,
type: 'partner-selection'
}
]