0

I am tring to use react-charts and the object they give as example data looks like this.

chartData: [
  {
    label: 'Series 1',
    data: [
      [0, 1],
      [1, 2],
      [2, 4],
      [3, 2],
      [4, 7],
    ],
  },
],

I want to build my own "data" and replace this temporary data but the whole object of arrays in objects in arrays (Or whatever it is confuses me.

Can someone explain the nesting here. Is it an array of 2 objects label and data and data` is an array of key value pairs. Is that accurate?

I'm kind of trying something like this...

   let myData = []
   res.data.payload.forEach(function (item, index) {
      console.log(item, index)
      myData[(index, item.odds)]
   })
   this.setState({ chartData[data]: myData })

Am I even close?

Thanks

1 Answer 1

1

You can do like this

   let myData = []
   res.data.payload.forEach(function (item, index) {
      console.log(item, index)
      myData.push([index, item.odds])
   })
   this.setState({ chartData: [{...this.state.chartData[0], data: myData}] })
Sign up to request clarification or add additional context in comments.

3 Comments

Key thing is to create new chartData array object.
try to console log myData
Sorry you had charData not chartData. All fixed Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.