I have tried without success to plot a simple line chart in DOJO using jSON data and would greatly appreciate any help.
I have the following snip of data being returned:
[{"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"}]
I have tried to plot directly from the data store, building an array, all to no avail. I'm very new to Dojo so I'm fairly sure I am making a simple mistake -
My code (as it currently exists is as follows):
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();
});
While it may not be obvious, I am trying to plot ID versus PnL.
If you want to bind the chart to a datastore, like you are doing, it is best to use the storeseries:
chart.addSeries("y", new StoreSeries(store, { query: {} }, "PnL"));
see: http://dojotoolkit.org/documentation/tutorials/1.7/charting_advanced/
for examples
You may also use dataseries:
addSeries("PnL", new dojox.charting.DataSeries(store, {query:{}}, "PnL")).
See: Dojox charting programattically using store series for a related question