开发者

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


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


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.)


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜