BaconJuice
BaconJuice

Reputation: 3779

How to push data object to Highcharts pie graph

I'm trying to push an object that looks like this to a highcharts pie chart.

Object {
    Kanye: 1,
    Tupac: 5,
    Biggie: 4,
    Jay Z: 3,
    Rick Ross: 2
}

I'm a bit confused how to turn this to an array that highchart accepts?

The following shows an example of how the array should be formatted

http://jsfiddle.net/gh/get/jquery/3.1.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/pie-basic/

Any help in clarification would be much appreciated!

Upvotes: 0

Views: 492

Answers (1)

Mike Johnson Jr
Mike Johnson Jr

Reputation: 796

You're going to want to make your object into an array of objects.

data = [{
    name: 'Kanye',
    y: 1,
}, {
    name: 'Tupac',
    y: 5,
}, { 
    name: 'Biggie',
    y: 4,
}, {
    name: 'Jay Z',
    y: 3,
}, {
    name: 'Rick Ross',
    y: 2,
}]

Upvotes: 1

Related Questions