OverviewDataPresentation is a widget that connects to a data store in a simple manner, and also provides some additional convenience mechanisms for connecting to common data sources without needing to explicitly construct a Dojo data store. The widget can then present the data in several forms: as a graphical chart, as a tabular grid, or as display panels presenting meta-data (title, creation information, etc) from the data. The widget can also create and manage several of these forms in one simple construction. Example 1 - Chart onlyThis example uses the following sample data, used to define the chart title, footer, range names and data values. var jsondata0 = {
"title" : "Softdrink Sales (2007)",
"footer" : "North America only",
"range" : [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
"series" : [
{ "legend" : "Cola", "values" : [ 35, 37, 44, 41, 43, 57, 62, 69, 74, 86, 101, 124 ] },
{ "legend" : "Lemonade", "values" : [ 122, 99, 111, 98, 82, 77, 76, 67, 72, 75, 66, 67 ] },
{ "legend" : "Dandelion", "values" : [ 99, 98, 98, 99, 97, 102, 100, 99, 102, 97, 95, 98 ] },
{ "legend" : "Ginger ale", "values" : [ 54, 59, 76, 84, 98, 110, 126, 121, 115, 109, 104, 99 ] },
{ "legend" : "Creme soda", "values" : [ 44, 58, 44, 36, 48, 54, 34, 38, 24, 56, 48, 34 ] },
{ "legend" : "Orangeade", "values" : [ 45, 25, 45, 31, 42, 33, 49, 34, 46, 25, 44, 37 ] },
{ "legend" : "Diet lemonade", "values" : [ 34, 17, 38, 13, 33, 14, 22, 39, 26, 17, 35, 21 ] },
{ "legend" : "Shandy", "values" : [ 14, 23, 16, 32, 12, 24, 18, 25, 13, 33, 15, 25 ] }
]
};
‘Series’ function This function is used to parse the above data and define which series and which properties are to be used for the chart. var makeseries = function(data){
return[ { datapoints: "range", name: "Month", type: "range", chart: false },
{ datapoints: "series[0].values", namefield: "series[0].legend" },
{ datapoints: "series[1].values", name: "Lemonade (fizzy)" },
{ datapoints: "series[2].values", namefield: "series[2].legend" },
{ datapoints: "series[3].values", namefield: "series[3].legend" }
];
}
Finally, create a DataPresentation object using the above data and series objects. The chart is placed in ‘chartdiv’, and the legend is placed in ‘legenddiv’. dojo.require("dojox.widget.DataPresentation");
dojo.require("dojox.charting.themes.Distinctive");
var dp;
dojo.ready(function(){
dp = new dojox.widget.DataPresentation("chartdiv", {
type: "chart",
chartType: "ClusteredColumns",
data: jsondata0,
series: makeseries(jsondata0),
legendNode: "legenddiv",
animate: true,
theme: "dojox.charting.themes.Distinctive"
});
});
<div id="legenddiv"></div>
<div id="chartdiv" style="width: 650px; height: 300px;"></div>
fig 1. RunSourceCollapse dojo.require("dojox.widget.DataPresentation");
dojo.require("dojox.charting.themes.Distinctive");
var jsondata0 = {
"title" : "Softdrink Sales (2007)",
"footer" : "North America only",
"range" : [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
"series" : [
{ "legend" : "Cola", "values" : [ 35, 37, 44, 41, 43, 57, 62, 69, 74, 86, 101, 124 ] },
{ "legend" : "Lemonade", "values" : [ 122, 99, 111, 98, 82, 77, 76, 67, 72, 75, 66, 67 ] },
{ "legend" : "Dandelion", "values" : [ 99, 98, 98, 99, 97, 102, 100, 99, 102, 97, 95, 98 ] },
{ "legend" : "Ginger ale", "values" : [ 54, 59, 76, 84, 98, 110, 126, 121, 115, 109, 104, 99 ] },
{ "legend" : "Creme soda", "values" : [ 44, 58, 44, 36, 48, 54, 34, 38, 24, 56, 48, 34 ] },
{ "legend" : "Orangeade", "values" : [ 45, 25, 45, 31, 42, 33, 49, 34, 46, 25, 44, 37 ] },
{ "legend" : "Diet lemonade", "values" : [ 34, 17, 38, 13, 33, 14, 22, 39, 26, 17, 35, 21 ] },
{ "legend" : "Shandy", "values" : [ 14, 23, 16, 32, 12, 24, 18, 25, 13, 33, 15, 25 ] }
]
};
var makeseries = function(data){
return[ { datapoints: "range", name: "Month", type: "range", chart: false },
{ datapoints: "series[0].values", namefield: "series[0].legend" },
{ datapoints: "series[1].values", name: "Lemonade (fizzy)" },
{ datapoints: "series[2].values", namefield: "series[2].legend" },
{ datapoints: "series[3].values", namefield: "series[3].legend" }
];
}
var dp;
dojo.ready(function(){
dp = new dojox.widget.DataPresentation("chartdiv", {
type: "chart",
chartType: "ClusteredColumns",
data: jsondata0,
series: makeseries(jsondata0),
legendNode: "legenddiv",
animate: true,
theme: "dojox.charting.themes.Distinctive"
});
});
<div id="legenddiv"></div>
<div id="chartdiv" style="width: 650px; height: 300px;"></div>
Example 2 - Chart and DataGridTo add a DataGrid to the above chart simply add the ‘gridNode’ property and target it at the relevant HTML element. RunSourceCollapse dojo.require("dojox.widget.DataPresentation");
dojo.require("dojox.charting.themes.Distinctive");
var dp;
dojo.ready(function(){
dp = new dojox.widget.DataPresentation("chartdiv", {
type: "chart",
chartType: "StackedColumns",
data: jsondata0,
series: makeseries(jsondata0),
legendNode: "legenddiv",
gridNode: "griddiv",
theme: "dojox.charting.themes.Distinctive"
});
});
<div id="legenddiv"></div>
<div id="chartdiv" style="width: 650px; height: 300px;"></div>
<div style="width:500px; height:300px;">
<div id="griddiv"></div>
</div>
fig 2. RunSourceCollapse dojo.require("dojox.widget.DataPresentation");
dojo.require("dojox.charting.themes.Distinctive");
var jsondata0 = {
"title" : "Softdrink Sales (2007)",
"footer" : "North America only",
"range" : [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
"series" : [
{ "legend" : "Cola", "values" : [ 35, 37, 44, 41, 43, 57, 62, 69, 74, 86, 101, 124 ] },
{ "legend" : "Lemonade", "values" : [ 122, 99, 111, 98, 82, 77, 76, 67, 72, 75, 66, 67 ] },
{ "legend" : "Dandelion", "values" : [ 99, 98, 98, 99, 97, 102, 100, 99, 102, 97, 95, 98 ] },
{ "legend" : "Ginger ale", "values" : [ 54, 59, 76, 84, 98, 110, 126, 121, 115, 109, 104, 99 ] },
{ "legend" : "Creme soda", "values" : [ 44, 58, 44, 36, 48, 54, 34, 38, 24, 56, 48, 34 ] },
{ "legend" : "Orangeade", "values" : [ 45, 25, 45, 31, 42, 33, 49, 34, 46, 25, 44, 37 ] },
{ "legend" : "Diet lemonade", "values" : [ 34, 17, 38, 13, 33, 14, 22, 39, 26, 17, 35, 21 ] },
{ "legend" : "Shandy", "values" : [ 14, 23, 16, 32, 12, 24, 18, 25, 13, 33, 15, 25 ] }
]
};
var makeseries = function(data){
return[ { datapoints: "range", name: "Month", type: "range", chart: false },
{ datapoints: "series[0].values", namefield: "series[0].legend" },
{ datapoints: "series[1].values", name: "Lemonade (fizzy)" },
{ datapoints: "series[2].values", namefield: "series[2].legend" },
{ datapoints: "series[3].values", namefield: "series[3].legend" }
];
};
var dp;
dojo.ready(function(){
dp = new dojox.widget.DataPresentation("chartdiv", {
type: "chart",
chartType: "StackedColumns",
data: jsondata0,
series: makeseries(jsondata0),
legendNode: "legenddiv",
gridNode: "griddiv",
theme: "dojox.charting.themes.Distinctive"
});
});
<div id="legenddiv"></div>
<div id="chartdiv" style="width: 650px; height: 300px;"></div>
<div style="width:500px; height:300px;">
<div id="griddiv"></div>
</div>
@import "{{ baseUrl }}dojox/grid/resources/Grid.css";
@import "{{ baseUrl }}dojox/grid/resources/{{ theme }}Grid.css";
.dojoxGrid table {
margin: 0;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
}
Example 3.To see how the widget can cope with different data shapes, switch from jsondata0 to jsondata1 as the input data. jsondata0 is structured as complete ‘series’ of values, gathered into an array with series titles. jsondata1 is structures as ‘data points’, each containing multiple sales values. var jsondata1 = {
"title" : "Softdrink Sales (2007)",
"footer" : "North America only",
"sales" : [
{ "month": "Jan", "cola": "84", "lemonade": "75", "dandelionandburdock": "64", "gingerale": "54" },
{ "month": "Feb", "cola": "108", "lemonade": "65", "dandelionandburdock": "47", "gingerale": "43" },
{ "month": "Mar", "cola": "24", "lemonade": "85", "dandelionandburdock": "68", "gingerale": "76" },
{ "month": "Apr", "cola": "56", "lemonade": "75", "dandelionandburdock": "73", "gingerale": "92" },
{ "month": "May", "cola": "78", "lemonade": "82", "dandelionandburdock": "43", "gingerale": "32" },
{ "month": "Jun", "cola": "124", "lemonade": "43", "dandelionandburdock": "34", "gingerale": "54" },
{ "month": "Jul", "cola": "84", "lemonade": "59", "dandelionandburdock": "42", "gingerale": "78" },
{ "month": "Aug", "cola": "108", "lemonade": "34", "dandelionandburdock": "69", "gingerale": "65" },
{ "month": "Sep", "cola": "24", "lemonade": "76", "dandelionandburdock": "86", "gingerale": "43" },
{ "month": "Oct", "cola": "56", "lemonade": "65", "dandelionandburdock": "77", "gingerale": "43" },
{ "month": "Nov", "cola": "78", "lemonade": "34", "dandelionandburdock": "65", "gingerale": "45" },
{ "month": "Dec", "cola": "124", "lemonade": "67", "dandelionandburdock": "41", "gingerale": "65" }
]
};
‘Series’ function. This function is used to parse the above data and define which series and which properties are to be used for the chart. var makeseries = function(data){
return [
{ datapoints: "sales", field: "month", name: "Month", type: "range", chart: false },
{ datapoints: "sales", field: "lemonade", name: "Lemonade (fizzy)" },
{ datapoints: "sales", field: "dandelionandburdock", name: "Dandelion and burdock" },
{ datapoints: "sales", field: "cola", name: "Cola" },
{ datapoints: "sales", field: "gingerale", name: "Ginger ale" }
];
}
dojo.require("dojox.widget.DataPresentation");
dojo.require("dojox.charting.themes.Distinctive");
var dp;
dojo.ready(function(){
dp = new dojox.widget.DataPresentation("chartdiv", {
type: "chart",
chartType: "StackedBars",
data: jsondata1,
refreshInterval: 3000,
series: makeseries(jsondata1),
legendNode: "legenddiv",
legendVertical: true,
gridNode: "griddiv",
titleNode: "title",
footerNode: "footer",
theme: "dojox.charting.themes.Distinctive"
});
});
<h1>Example 3.</h1>
<div style="width:600px; text-align: center;">
<h2 id="title" style="margin-bottom: 0;"></h2>
<p id="footer" style="color: gray; font-size: 0.85em; margin-top: 0.2em;"></p>
</div>
<table border="0"><tr valign="top">
<td>
<div id="chartdiv" style="width: 400px; height: 300px;"></div>
</td>
<td>
<div style="border: 1px solid #888888; padding: 5px; background-color: rgba(255, 255, 221, 0.8);">
<div id="legenddiv" ></div>
</div>
</td>
</tr></table>
<div style="width:400px; height:300px; padding-left: 100px;">
<div id="griddiv"></div>
</div>
fig 3. ![]() Propertiesstore: Object
query: String
queryOptions: String
data: Object
url: String
urlError: function
refreshInterval: Number
refreshIntervalPending:
series: Array
type: String
chartType: String
reverse: Boolean
animate: Object
labelMod: Integer
legendVertical: Boolean
theme: String|Theme
chartNode: String|DomNode
legendNode: String|DomNode
gridNode: String|DomNode
titleNode: String|DomNode
chartWidget: Object
legendWidget: Object
gridWidget: Object
|
|
来自: LibraryPKU > 《Web》