I try hard to get some functional charts with dojo...
I want to create a stacked area chart with 3 lines. For the "bas", "moy" and "haut" as you see in the JSON data.
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}]
};
I want to put int the x axis the months as it seen in the code. Call the specific data in the JSON to create every line.
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();
});
It doesn't work, I don't know wath I have to put instead of (jStore, {query: {haut: "*"}}, "haut")
to call my specific data.
please help ! thanx a lot.
From the official docs Using dojo.data Data Sources with Charts:
dojox.charting.DataSeries is used to connect to dojo.data stores. User should create it and pass it instead of a data array in chart.addSeries() call.
Example of use can be found in dojox/charting/tests/test_DataSeries.html
.
Another missing piece in your example is a store object. Somehow you try to pass a JSON structure around, which has data, but no required methods. You should create a data store first from your data. I have no idea what data store you want to use, but if all you want is to show your data structure, you can use 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'}
);
Use link above to learn about dojox.charting.DataSeries
. Read all about dojo.data
in the official documentation: http://docs.dojocampus.org/dojo/data
精彩评论