0

我曾尝试使用 JSON 数据在 DOJO 中绘制一个简单的折线图但没有成功,非常感谢任何帮助。

我返回了以下数据片段:

[{"id":"24","Entry":"2012-02-10","Symbol":"Various","Type":"Speculativ","Call1":"0","Call2":"0","Put1":"0","Put2":"0","Cost":"0.00","Qty":"0","PnL":"383","R":"0.00","Risk":"6691"},    
{"id":"23","Entry":"2012-02-01","Symbol":"VariousSp","Type":"Vertical","Call1":"0","Call2":"0","Put1":"0","Put2":"0","Cost":"0.00","Qty":"0","PnL":"341","R":"0.00","Risk":"19160"}]

我试图直接从数据存储中绘制,构建一个数组,但都无济于事。我对Dojo很陌生,所以我很确定我犯了一个简单的错误-

我的代码(目前存在如下):

var PnLStore;
    var cumPnL = [];

    require([
            "dojox/charting/Chart",
            "dojo/store/JsonRest",
            "dojo/store/Memory",
            "dojo/store/Cache",
            "dojox/charting/StoreSeries",
            "dojox/charting/plot2d/Lines",
            "dojox/charting/axis2d/Default",
            "dojox/charting/themes/Dollar",
            "dojox/charting/plot2d/Markers",
            "dojo/domReady!"],

            function( Chart, JsonRest, Memory, Cache, StoreSeries, Lines) {

                    PnLStore = Cache(JsonRest({target:"pullTradesClosed.php"}), Memory());

                    var chart = new Chart("chartDiv");

                    chart.addPlot("default", {
                            type: "Lines",
                            markers: true
                    });

                    chart.addAxis("x");
                    chart.addAxis("y", { vertical: true, fixLower: "major", fixUpper: "major" });

                    PnLStore.query({id:"id"}).forEach(
                      function(trade) {
                        cumPnL.push (Number(trade.PnL));
                    });

                    chart.addSeries("PnL", cumPnL, {stroke:"green"});
                    chart.render(); 

            });

虽然它可能并不明显,但我正在尝试绘制 ID 与 PnL 的关系。

4

1 回答 1

0

如果您想将图表绑定到数据存储区,就像您正在做的那样,最好使用 storeseries:

chart.addSeries("y", new StoreSeries(store, { query: {} }, "PnL"));

见: http ://dojotoolkit.org/documentation/tutorials/1.7/charting_advanced/

举些例子

您还可以使用数据系列:

addSeries("PnL", new dojox.charting.DataSeries(store, {query:{}}, "PnL"))。

请参阅: Dojox 使用商店系列以编程方式绘制图表 以获取相关问题

于 2012-04-05T15:46:19.670 回答