Skip to content Skip to sidebar Skip to footer

How Do I Iterate Through An Array Of Objects And Display Each Objects Into A Chart?

I am trying to create a dashboard using React, The first part is showing my local API data. This is being fetched from the front end using ComponentDidMount and using splice to onl

Solution 1:

So the issue here is that you are iterating over data, thus making a chart for each entry when, if I understand correctly, you want to combine it all into one chart. So instead of iterating over data directly, you would want to iterate over data in the prop passed to Chart. So the code would look something like this

<Chart
  data={[
    ['', 'UPLIFT', 'PCT_UPLIFT'],
    ...data.map(d => [ d.PRODUCT, d.UPLIFT, d.PCT_UPLIFT ])
  ]}
/>

Post a Comment for "How Do I Iterate Through An Array Of Objects And Display Each Objects Into A Chart?"