我曾尝试使用 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 的关系。