I want to iterate through my data object array and return a Bar item for each property, but for some reason rendering does not occur when attempted through mapping.
Heres my code snippet:
const staticData = [{name: '0-30 days', 'To Do': 4000, 'Doing': 2003}, {name: '31-60 days', 'To Do': 1000, 'Doing': 1200}, {name: '61-90 days', 'To Do': 2500, 'Doing': 1500}, {name: '91+ days', 'To Do': 4000, 'Doing': 2400}];
<BarChart width={340} height={180} data={staticData}
margin={{top: 5, right: 30, left: -30, bottom: 0}}>
<CartesianGrid strokeDasharray="3 3 "/>
<XAxis dataKey="name" interval={0} tick={{fontSize: 8}}/>
<YAxis tick={{fontSize: 8}} allowDataOverflow={true}/>
<Tooltip/>
{
staticData.map((element) => {
Object.keys(element).map((s) => {
if (s!=="name"){
return (
<Bar barSize={30} dataKey={s} name={s} key={s} stackId="a" fill="#449FDB" />
);
}
return "";
});
return "";
})
}
</BarChart>
If I output the values to console, it shows that they are being picked up:
If i replace the iteration with this approach, it works:
<Bar barSize={30} dataKey="To Do" stackId="a" fill="#449FDB" />
<Bar barSize={30} dataKey="Doing" stackId="a"fill="#E67E23" />
The reason I need the iterative approach is because in practice I will be receiving data from an API, and its DataKey properties will vary.
What am I doing wrong?
Thanks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…