Gui
Gui

Reputation: 9823

Question about javascript objects

I'm trying to use a jQuery plugin, the HighCharts, calling the series from a webservice but i don't know how to use the javascript javascript that i'm filling.

I've created the object like this:

chartOjb = new Object();

Then i create two properties:name and data. (i've already tested if i'm getting the values properly with alerts(); and everyting is ok).

In HighCharts examples, they fill the series like this:

     series: [{
        name: 'Jane',
        data: [1, 0, 4]
     }, {
        name: 'John',
        data: [5, 7, 3]
     }]

I've tried to do something like this:

series: chartObj

But that doesn't work. What would be the proper way to do this? The example that i'm trying to follow is here: http://www.highcharts.com/documentation/how-to-use

Thanks

Upvotes: -1

Views: 110

Answers (3)

Jacob Relkin
Jacob Relkin

Reputation: 163318

var chartObj = {};
chartObj['name'] = 'Jane';
chartObj['data'] = [1,0,4];

var otherChartObj = {};
otherChartObj['name'] = 'John';
otherChartObj['data'] = [5,7,3];

Wrap these objects in an array:

series:[chartObj, otherChartObj]

Upvotes: 1

Sean Vieira
Sean Vieira

Reputation: 160073

The only thing you need to change is to wrap your chartObj in an array.

series: chartObj

changes to

series: [chartObj]

series needs to be an array of objects to use (one for each series.)

Upvotes: 1

hvgotcodes
hvgotcodes

Reputation: 120318

You are passing a single object, whereas the API wants an array (i gather from your example). So something like:

series: [charObj1, chartObj2]

should do the trick

Upvotes: 3

Related Questions