如何在 Dojo Spider Chart 的 addSeries() 方法中传递 JSON 对象

发布于 2024-11-29 02:13:58 字数 1568 浏览 0 评论 0原文

我正在尝试使用 dojo 图表库实现蜘蛛图。我正在使用 dojo 中的一个虚拟示例:http://archive。 dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_spider2d.html

它使用这样的 addSeries 方法:

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

chart1.render();

但我想动态传递数据。我得到的数据如下:

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"
    }
];

我得到了 obj2 以及具有相同结构但具有不同 qAns 值的 obj2。
所以我想使用 obj1 和 obj2 代替上面示例中给出的“中国”和“法国”。
所以我想要类似的东西

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" });

,你能帮我一下,我应该使用什么语法在 addSeries 方法中传递 obj 变量吗?我有一个小想法,我需要将它用作 JSON 对象并将其转换为数据存储并传入数据存储,但我无法使语法正常工作。

请帮忙!非常感谢。 问候

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 use 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙温凉少女 2024-12-06 02:13:58

我从未使用过图表,但我会寻找一些与数据网格相关的更广泛的示例。例如,请参见此处: Dojo 网格嵌套 json

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

爱人如己 2024-12-06 02:13:58

谢谢,通过使用以下内容使其工作:

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

AND data1[0] 是动态创建的 json 对象,如 {'Label1':Value1, 'Label2':Value2...等。 }

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文