1

I've recently started learning React. Anyways,I want to insert data in scatter chart which requires one two dimensional variable named "data". However, I don't know how to create it because I already have another one dimensional array. Tried something like this:

copyToFinal() {
        const  data = [
            this.state.arrayvar.map((number, index) =>
            {x:index, y:number})
        ];
    }

It's a function that creates a variable from array (arrayvar). I need an array which would fit for the graph library or maybe You could suggest any other way to insert my array into the graph which requires x and y values:

<ScatterChart min={null} max={null} data={data} xtitle="Index" ytitle="Random Numbers" /

1 Answer 1

1

You are not actually returning an object from your mapping function.

Try this:

const data = [
  this.state.arrayvar.map((number, index) => {
    return { x: index, y: number }
  })
]

...or:

const data = [
  this.state.arrayvar.map((number, index) =>
    ({ x: index, y: number })
  )
]
Sign up to request clarification or add additional context in comments.

Comments

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.