问题描述
- 根据所选的条件,将数组对象转化为符合echart中的配置
2.
问题出现的环境背景
1.尝试过用map去遍历源数组然后把data ,push到里面去,如果是没有条件筛选是没用问题的,但是现在需要作筛选去匹配对应的数据,很迷茫,弄了好久没得出来。
如下尝试代码:
`
const totalResult =arr.map(item=>{
let sourceData =[];
sourceData.push(item.oneday,item.twoday,item.threeday,item.fourday,item.fiveday)
let obj={};
obj.type='bar';
obj.name=item.name;
obj.data =sourceData
return obj
})
console.log("totalResult",totalResult)
`
相关数据代码
说明:1.数据不止小明和小红两个对象。 2.小明或小红的字段也不止以下几个
`
let arr=[
{
name:'小明',
oneday: '1.20',
twoday : '2.20',
threeday: '3.20',
fourday: '4.20',
fiveday: '5.20',
January: '2.20',
february : '2.30',
March: '2.40',
April: '2.50',
May : '2.60',
},
{
name:'小红',
oneday: '2.20',
twoday : '1.20',
threeday: '4.20',
fourday: '5.20',
fiveday: '6.20',
January: '2.90',
february : '3.20',
March: '5.20',
April: '6.20',
May : '9.20'
}
]
const arr1 =['一天','两天','五天']
`
你期待的结果是:
期望的结果如图: