如何在 Dojo Spider Chart 的 addSeries() 方法中传递 JSON 对象
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未使用过图表,但我会寻找一些与数据网格相关的更广泛的示例。例如,请参见此处: 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
谢谢,通过使用以下内容使其工作:
AND
data1[0]
是动态创建的 json 对象,如{'Label1':Value1, 'Label2':Value2...等。 }
Thanks, made it to work by using something like:
AND
data1[0]
is the json object created dynamically like{'Label1':Value1, 'Label2':Value2...etc.}