开发者

how to pass JSON object in addSeries() method for Dojo Spider Chart

I am trying to implement a Spider Chart using dojo chart library. I am using a dummy example from dojo: http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_spider2d.html

It uses the addSeries method like this:

chart1.addSeries("China", {data: {"GDP": 2,"area": 6,"population": 2000,"inflation": 15,"growth": 12}}, { fill: "blue" });
chart1.addSeries("France", {data: {"GDP": 6,"area": 15,"population": 500,"inflation": 5,"growth": 6}}, { fill: "red" });
chart1.addSeries("USA", {data: {"GDP": 3,"area": 20,"population": 1500,"inflation": 10,"growth": 3}}, { fill: "green" });

..and so on..

chart1.render();

But I want to pass in the data dynamically. I have got my data something like following:

var obj1 = [{
        "qNo": "THR1", 
        "qAns": "3"
    }, {
        "qNo": "THR2", 
        "qAns": "3"
    }, {
        "qNo": "THR3", 
        "qAns": "1"
    }, {
        "qNo": "THR4", 
        "qAns": "3"
    }, {
        "qNo": "THR5", 
        "qAns": "3"
    }, {
        "qNo": "THR7", 
        "qAns": "3"
    }
];

I have got obj2 as well of same structure but with different qAns values.

So I want to us开发者_Go百科e obj1 and obj2 in place of "China" and "France" as given in the example above.

So i want something like

chart1.addSeries("obj1", {data: {obj1 data needs to go here but how?}}, { fill: "blue" });
chart1.addSeries("obj2", {data: {obj1 data needs to go here but how?}}, { fill: "red" });

Can you please help me what syntax shall I use to pass in obj variables in addSeries method? I have a small idea that i need to use it as JSON object and convert it to datastore and pass in the datastore, but I am unable to get the syntax working.

Please help ! thanx a lot. Regards


I have never worked with charts but I would look for some examples related to DataGrids that are a bit more widespread. See for example here: Dojo grid nested json


Thanks, made it to work by using something like:

chart1.addSeries("SeriesName", data1[0], { fill: "transparent" }); 

AND data1[0] is the json object created dynamically like {'Label1':Value1, 'Label2':Value2...etc.}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜