AddSeries参数

时间:2010-09-28 07:30:46

标签: json dojo charts dojox.charting

我努力用dojo获得一些功能图表......

我想创建一个包含3行的堆积区域图表。对于你在JSON数据中看到的“bas”,“moy”和“haut”。

    var jStore = {"identifier":"mois",
                "items":[{"mois":1,  "bas":98,   "moy":122.5,   "haut":147},
                         {"mois":2,  "bas":91,   "moy":113.75,  "haut":136.5},
                         {"mois":3,  "bas":91,   "moy":113.75,  "haut":136.5},
                         {"mois":4,  "bas":84,   "moy":105,     "haut":126},
                         {"mois":5,  "bas":77,   "moy":96.25,   "haut":115.5},
                         {"mois":6,  "bas":63,   "moy":78.75,   "haut":94.5},
                         {"mois":7,  "bas":49,   "moy":61.25,   "haut":73.5},
                         {"mois":8,  "bas":42,   "moy":52.5,    "haut":63},
                         {"mois":9,  "bas":49,   "moy":61.25,   "haut":73.5},
                         {"mois":10, "bas":70,   "moy":87.5,    "haut":105},
                         {"mois":11, "bas":77,   "moy":96.25,   "haut":115.5},
                         {"mois":12, "bas":84,   "moy":105,     "haut":126}]
             };

我想把x轴放在代码中看到的月份。调用JSON中的特定数据来创建每一行。

dojo.addOnLoad(function() {
                var chart1 = new dojox.charting.Chart2D('chart1');
                chart1.addPlot('default', {
                        type: 'StackedAreas',
                        markers: true,
                        tension: 'S',
                        lines: true,
                        areas: true,
                        labelOffset: -30,
                        shadows: {
                            dx:2, dy:2, dw:2
                        }
                     });
                chart1.addAxis('x', {max:12, 
                   labels:[
                      {value: 0, text: ""},
                      {value: 1, text: "Jan"},
                      {value: 2, text: "Feb"},
                      {value: 3, text: "Mar"},
                      {value: 4, text: "Apr"},
                      {value: 5, text: "May"},
                      {value: 6, text: "Jun"},
                      {value: 7, text: "Jul"},
                      {value: 8, text: "Aug"},
                      {value: 9, text: "Sept"},
                      {value: 10, text: "Oct"},
                      {value: 11, text: "Nov"},
                      {value: 12, text: "Dec"}
               ]});
                chart1.addAxis('y', { vertical: true, max:200, includeZero: true });
                chart1.addSeries('Basse', (jStore, {query: {bas: "*"}}, "bas"),{ stroke: 'red', fill: 'pink' });
                chart1.addSeries('Moyenne',(jStore, {query: {moy: "*"}}, "moy"), { stroke: 'green', fill: 'lightgreen' });
                chart1.addSeries('Haute',(jStore, {query: {haut: "*"}}, "haut"), { stroke: 'blue', fill: 'lightblue' });
                chart1.render();
                var anim1a = new dojox.charting.action2d.Magnify(chart1, "default");
                var anim1b = new dojox.charting.action2d.Tooltip(chart1, "default");
                var legend1 = new dojox.charting.widget.Legend({
                    chart:chart1
                },"legend1");
                chart1.render();
            });

它不起作用,我不知道我必须代替(jStore, {query: {haut: "*"}}, "haut")来调用我的特定数据。

请帮忙!非常感谢。

1 个答案:

答案 0 :(得分:1)

来自官方文档Using dojo.data Data Sources with Charts

  

dojox.charting.DataSeries用于连接dojo.data存储。用户应该创建它并在chart.addSeries()调用中传递它而不是数据数组。

使用示例可在dojox/charting/tests/test_DataSeries.html

中找到

您示例中的另一个缺失部分是商店对象。不知何故,你试图传递一个JSON结构,它有数据,但没有必要的方法。您应该首先从数据创建数据存储。我不知道您要使用哪个数据存储,但如果您想要显示数据结构,则可以使用dojo.data.ItemFileReadStore

dojo.require("dojo.data.ItemFileReadStore");

var jStore = ...; // not really a store, but your JSON-like object
var realStore = new dojo.data.ItemFileReadStore({data: jStore});
...
chart1.addSeries(
  'Basse',
  new dojox.charting.DataSeries(realStore, {query: {bas: "*"}}, "bas"),
  {stroke: 'red', fill: 'pink'}
);

使用上面的链接了解dojox.charting.DataSeries。阅读官方文档中的所有dojo.datahttp://docs.dojocampus.org/dojo/data