原数据:
let arr = [
{
time:'2022-05-第3周',
name: undefined,
type: 'bar',
stack: 'Ad',
label: {
show: true,
position: 'inside'
},
str: 0
},
{
time:'2022-05-第3周',
name: undefined,
type: 'bar',
stack: 'Ad',
label: {
show: true,
position: 'inside'
},
str: 0
},
{
time:'2022-05-第4周',
name: undefined,
type: 'bar',
stack: 'Ad',
label: {
show: true,
position: 'inside'
},
str: 0
},
{
time:'2022-05-第4周',
name: '失败',
type: 'bar',
stack: 'Ad',
label: {
show: true,
position: 'inside'
},
str: 1
},
{
time:'2022-05-第4周',
name: '成功',
type: 'bar',
stack: 'Ad',
label: {
show: true,
position: 'inside'
},
str: 1
}
]
目标数据:
targetArr=[
{
name: '成功', //根据name合并str到data(相同time的str要相加)
type: 'bar',
stack: 'Ad',
label: {
show: true,
position: 'inside'
},
data:[0,1]//根据time将相加后的str存入data(顺序就对应time顺序)
},
{
name: '失败',
type: 'bar',
stack: 'Ad',
label: {
show: true,
position: 'inside'
},
data:[0,1]
}
]