0

I am using highchart to create a graph. I have a javsascript object like this

test1:38
test2:2
test3:160

I want to create a piechart with the values of this object something like this

series: [{

          name: 'Success',
          data: [
          {name:"test1", y:1},
         {name:"test2", y:38},
         {name:"test3", y:k},]
}]

How can I create the data array like this using my javascript object.I am new to javascript so any help would be appreciated.

1 Answer 1

1

You could map the entries of the object to get the data array

const input = {
  test1: 38,
  test2: 2,
  test3: 160
}

const data = Object.entries(input)
                   .map(([name, y]) => ({ name, y }))

console.log(data)

const chart = {
  series: [{
    name: 'Success',
    data
  }]
}

console.log(chart)

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.