=== modified file 'src/docbkx/en/dhis2_user_man_web_api.xml' --- src/docbkx/en/dhis2_user_man_web_api.xml 2013-11-07 11:54:03 +0000 +++ src/docbkx/en/dhis2_user_man_web_api.xml 2013-11-07 19:03:46 +0000 @@ -1089,47 +1089,252 @@ api/reports/OeJsA6K1Otx/data.pdf api/reports/OeJsA6K1Otx/data.pdf?date=2012-01-01 + + + + +
+ Embedding pivot tables with the Pivot table plug-in + In this example we will see how we can embed good-looking, light-weight html pivot tables with data served from a DHIS back-end into a Web page. To accomplish this we will use the Pivot table plug-in. The plug-in is written in Javascript and depends on the Ext JS library only. A complete working example can be found at . Open the page in a web browser and view the source to see how it is set up. + We start by including three files in the header section of the HTML document. The first two files are the Ext JS javascript library (we use the Google content delivery network in this case) and its css stylesheet. The third file is the Pivot table plug-in. Make sure the path is pointing to your DHIS server installation. + <link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/ + svn/tags/extjs-4.0.7/release/resources/css/ext-plugin-gray.css" /> + + <script src="http://extjs-public.googlecode.com/svn/tags/extjs-4.0.7/release/ + ext-all.js"></script> + + <script src="http://apps.dhis2.org/demo/dhis-web-commons/javascripts/plugin/ + table.js"></script> + To authenticate with the DHIS server we use the same approach as in the previous section. In the header of the HTML document we include the following Javascript inside a script element. The setLinks method will be implemented later. Make sure the base variable is pointing to your DHIS installation. + var base = "http://apps.dhis2.org/demo/"; + + Ext.onReady( function() { + Ext.Ajax.request({ + url: base + "dhis-web-commons-security/login.action", + method: "POST", + params: { j_username: "portal", j_password: "Portal123" }, + success: setLinks + }); + }); + Now let us have a look at the various options for the Pivot table plug-in. Two properies are required: el and url (please refer to the table below). Now, if you want to refer to pre-defined tables already made inside DHIS it is sufficient to provide the additional id parameter. If you instead want to configure a pivot table dynamically you shoud omit the id parameter and provide data dimensions inside a columns array (chart series), a rows array (chart categories) and optionally a filters array instead. + + A data dimension is defined as an object with a text property called dimension. This property accepts the following values: in (indicator), de (data element), ds (data set), dc (data element operand), pe (period), ou (organisation unit) or the id of any organisation unit group set or data element group set (can be found in the web api). The data dimension also has an array property called items which accepts objects with an id property. + + To sum up, if you want to have e.g. "ANC 1 Coverage", "ANC 2 Coverage" and "ANC 3 Coverage" on the columns in your chart you can make the following columns config: + + columns: [{ + dimension: "in", // "in", "de", "ds", "dc", "pe", "ou" or any dimension id + items: [ + {id: "Uvn6LCg7dVU"}, // the id of ANC 1 Coverage + {id: "OdiHJayrsKo"}, // the id of ANC 2 Coverage + {id: "sB79w2hiLp8"} // the id of ANC 3 Coverage + ] + }] + + + Pivot table plug-in configuration + + + + + Param + + + Type + + + Required + + + Options (default first) + + + Description + + + + + + el + string + Yes + + Identifier of the HTML element to render the chart in your web page + + + url + string + Yes + + Base URL of the DHIS server + + + id + string + No + + Identifier of a pre-defined chart (favorite) in DHIS + + + columns + array + Yes (if no id provided) + + Data dimensions to include in chart as series + + + rows + array + Yes (if no id provided) + + Data dimensions to include in chart as category + + + filter + array + No + + Data dimensions to include in chart as filters + + + showTotals + boolean + No + true | false + Whether to display totals for columns and rows + + + showSubTotals + boolean + No + true | false + Whether to display sub-totals for columns and rows + + + hideEmptyRows + boolean + No + false | true + Whether to hide rows with no data + + + showHierarchy + boolean + No + false | true + Whether to extend orgunit names with the name of all anchestors + + + displayDensity + string + No + "normal" | "comfortable" | "compact" + The amount of space inside table cells + + + fontSize + string + No + "normal" | "large" | "small" + Table font size + + + digitGroupSeparator + string + No + "space" | "comma" | "none" + How values are formatted: 1 000 | 1,000 | 1000 + + + legendSet + object + No + + Show a color indicator next to the values (currently reusing legend sets from GIS) + + + +
+ We continue by adding one pre-defined and one dynamic pivot table to our HTML document. You can browse the list of available pivot tables using the Web API here: . + function setLinks() { + DV.plugin.getTable({ url: base, el: 'chartA1', id: 'R0DVGvXDUNP' }); + + DV.plugin.getTable({ + url: base, + el: 'chartB1', + type: 'stackedBar', + columns: [ + {dimension: 'de', items: [{id: 'YtbsuPPo010'}, {id: 'l6byfWFUGaP'}]} + ], + rows: [ + {dimension: 'pe', items: [{id: 'LAST_12_MONTHS'}]} + ], + filters: [ + {dimension: 'ou', items: [{id: 'USER_ORGUNIT'}]} + ], + //showTotals: false, + //showSubTotals: false, + //hideEmptyRows: true, + //showHierarchy: true, + //displayDensity: "comfortable", + //fontSize: "large", + //digitGroupSeparator: "comma", + //legendSet: {id: "BtxOoQuLyg1"} + }); + }; + Finally we include some div elements in the body section of the HTML document with the identifiers referred to in the plug-in Javascript. + <div id="tableA1" class="chart"></div> + <div id="tableB1" class="chart"></div> + To see a complete working example please visit . +
+ + + + + + + + + + +
Embedding charts with the Visualizer chart plug-in In this example we will see how we can embed good-looking Ext JS charts () with data served from a DHIS back-end into a Web page. To accomplish this we will use the DHIS Visualizer plug-in. The plug-in is written in Javascript and depends on the Ext JS library only. A complete working example can be found at . Open the page in a web browser and view the source to see how it is set up. - We start by including three required Javascript files in the header section of the HTML document. The first file is the Ext JS Javascript library (we use the Google content delivery network in this case). The third file is the Visualizer plug-in. Make sure the path is pointing to your DHIS server installation. - <script type="text/javascript" - src="http://extjs-public.googlecode.com/svn/tags/extjs-4.0.7/release/ext-all.js"> -</script> -<script type="text/javascript" - src="http://apps.dhis2.org/demo/dhis-web-commons/javascripts/plugin/chart.js"> -</script> - To authenticate with the DHIS 2 server we use the same approach as in the previous - section. In the header of the HTML document we include the following Javascript inside a - script element. The setLinks method will be implemented - later. Make sure the base variable is pointing to your DHIS - installation. - var base = 'http://apps.dhis2.org/demo/'; - -Ext.onReady( function() { - Ext.Ajax.request({ - url: base + "dhis-web-commons-security/login.action", - method: 'POST', - params: { j_username: "portal", j_password: "Portal123" }, - success: setLinks - }); -}); - Now let us have a look at the various options for the Visualizer plug-in. Two properies are required: el and url (please refer to the table below). If you want to refer to pre-defined charts already made inside DHIS it is sufficient to provide the additional id parameter. If you want to create dynamic charts you shoud omit the id parameter and provide data dimensions inside a columns array (chart series), a rows array (chart categories) and optionally a filters array instead. + We start by including three files in the header section of the HTML document. The first two files are the Ext JS javascript library (we use the Google content delivery network in this case) and its stylesheet. The third file is the Visualizer plug-in. Make sure the path is pointing to your DHIS server installation. + <link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/ + svn/tags/extjs-4.0.7/release/resources/css/ext-plugin-gray.css" /> + + <script src="http://extjs-public.googlecode.com/svn/tags/extjs-4.0.7/release/ + ext-all.js"></script> + + <script src="http://apps.dhis2.org/demo/dhis-web-commons/javascripts/plugin/ + table.js"></script> + To authenticate with the DHIS server we use the same approach as in the previous section. In the header of the HTML document we include the following Javascript inside a script element. The setLinks method will be implemented later. Make sure the base variable is pointing to your DHIS installation. + var base = "http://apps.dhis2.org/demo/"; + + Ext.onReady( function() { + Ext.Ajax.request({ + url: base + "dhis-web-commons-security/login.action", + method: "POST", + params: { j_username: "portal", j_password: "Portal123" }, + success: setLinks + }); + }); + Now let us have a look at the various options for the Visualizer plug-in. Two properies are required: el and url (please refer to the table below). Now, if you want to refer to pre-defined charts already made inside DHIS it is sufficient to provide the additional id parameter. If you instead want to configure a chart dynamically you shoud omit the id parameter and provide data dimensions inside a columns array (chart series), a rows array (chart categories) and optionally a filters array instead. A data dimension is defined as an object with a text property called dimension. This property accepts the following values: in (indicator), de (data element), ds (data set), dc (data element operand), pe (period), ou (organisation unit) or the id of any organisation unit group set or data element group set (can be found in the web api). The data dimension also has an array property called items which accepts objects with an id property. To sum up, if you want to have e.g. "ANC 1 Coverage", "ANC 2 Coverage" and "ANC 3 Coverage" as series in your chart you can make the following columns config: - -columns: [{ - dimension: "in", - items: [ - {id: "Uvn6LCg7dVU"}, - {id: "OdiHJayrsKo"}, - {id: "sB79w2hiLp8"} - ] -}] - + columns: [{ + dimension: "in", // could be "in", "de", "ds", "dc", "pe", "ou" or any dimension id + items: [ + {id: "Uvn6LCg7dVU"}, // the id of ANC 1 Coverage + {id: "OdiHJayrsKo"}, // the id of ANC 2 Coverage + {id: "sB79w2hiLp8"} // the id of ANC 3 Coverage + ] + }] Visualizer chart plug-in configuration @@ -1202,7 +1407,8 @@ No Data dimensions to include in chart as filters - + + showData boolean No @@ -1290,40 +1496,295 @@
We continue by including two pre-defined charts and to dynamic charts to our HTML document. You can browse the list of available charts using the Web API here: . - -function setLinks() { - DV.plugin.getChart({ url: base, el: 'chartA1', id: 'R0DVGvXDUNP' }); + function setLinks() { + DV.plugin.getChart({ url: base, el: 'chartA1', id: 'R0DVGvXDUNP' }); - DV.plugin.getChart({ - url: base, - el: 'chartB1', - type: 'stackedBar', - columns: [ - {dimension: 'de', items: [{id: 'YtbsuPPo010'}, {id: 'l6byfWFUGaP'}, {id: 's46m5MS0hxu'}]} - ], - rows: [ - {dimension: 'pe', items: [{id: 'LAST_12_MONTHS'}]} - ], - filters: [ - {dimension: 'ou', items: [{id: 'USER_ORGUNIT'}]} - ], - showData: false, - //targetLineValue: 70, - //baseLineValue: 20, - //showTrendLine: true, - //hideLegend: true, - //title: 'My chart title', - //domainAxisTitle: 'Periods', - //rangeAxisTitle: 'Percent' - }); -}; + DV.plugin.getChart({ + url: base, + el: 'chartB1', + type: 'stackedBar', + columns: [ + {dimension: 'de', items: [{id: 'YtbsuPPo010'}, {id: 'l6byfWFUGaP'}, {id: 's46m5MS0hxu'}]} + ], + rows: [ + {dimension: 'pe', items: [{id: 'LAST_12_MONTHS'}]} + ], + filters: [ + {dimension: 'ou', items: [{id: 'USER_ORGUNIT'}]} + ], + showData: false, + //targetLineValue: 70, + //baseLineValue: 20, + //showTrendLine: true, + //hideLegend: true, + //title: 'My chart title', + //domainAxisTitle: 'Periods', + //rangeAxisTitle: 'Percent' + }); + }; Finally we include some div elements in the body section of the HTML document with the identifiers referred to in the plug-in Javascript. - -<div id="chartA1" class="chart"></div> -<div id="chartB1" class="chart"></div> + <div id="chartA1" class="chart"></div> + <div id="chartB1" class="chart"></div> To see a complete working example please visit .
+ + + + + + + + + + + + + + +
+ Embedding maps with the GIS map plug-in + In this example we will see how we can embed maps with data served from a DHIS back-end into a Web page. To accomplish this we will use the GIS map plug-in. The plug-in is written in Javascript and depends on the Ext JS library only. A complete working example can be found at . Open the page in a web browser and view the source to see how it is set up. + We start by including four files and Google Maps in the header section of the HTML document. The first two files are the Ext JS javascript library (we use the Google content delivery network in this case) and its stylesheet. The third file is the OpenLayers javascript mapping framework () and finally we include the GIS map plug-in. Make sure the path is pointing to your DHIS server installation. + <link rel="stylesheet" type="text/css" href="http://extjs-public.googlecode.com/ + svn/tags/extjs-4.0.7/release/resources/css/ext-plugin-gray.css" /> + + <script src="http://extjs-public.googlecode.com/svn/tags/extjs-4.0.7/release/ + ext-all.js"></script> + + <script src="https://maps.google.com/maps/api/js?sensor=false"></script> + + <script src="http://apps.dhis2.org/demo/dhis-web-commons/javascripts/openlayers/ + OpenLayers.js"></script> + + <script src="http://apps.dhis2.org/demo/dhis-web-commons/javascripts/plugin/ + map.js"></script> + + To authenticate with the DHIS server we use the same approach as in the previous section. In the header of the HTML document we include the following Javascript inside a script element. The setLinks method will be implemented later. Make sure the base variable is pointing to your DHIS installation. + var base = "http://apps.dhis2.org/demo/"; + + Ext.onReady( function() { + Ext.Ajax.request({ + url: base + "dhis-web-commons-security/login.action", + method: "POST", + params: { j_username: "portal", j_password: "Portal123" }, + success: setLinks + }); + }); + Now let us have a look at the various options for the GIS plug-in. Two properies are required: el and url (please refer to the table below). Now, if you want to refer to pre-defined charts already made inside DHIS it is sufficient to provide the additional id parameter. If you instead want to configure a chart dynamically you shoud omit the id parameter and provide mapViews (layers) instead. They should be configured with data dimensions inside a columns array (chart series), a rows array (chart categories) and optionally a filters array instead. + + A data dimension is defined as an object with a text property called dimension. This property accepts the following values: in (indicator), de (data element), ds (data set), dc (data element operand), pe (period), ou (organisation unit) or the id of any organisation unit group set or data element group set (can be found in the web api). The data dimension also has an array property called items which accepts objects with an id property. + + To sum up, if you want to have a layer with e.g. "ANC 1 Coverage" in your map you can make the following columns config: + + columns: [{ + dimension: "in", // could be "in", "de", "ds", "dc", "pe", "ou" or any dimension id + items: [{id: "Uvn6LCg7dVU"}], // the id of ANC 1 Coverage + }] + + + Visualizer chart plug-in configuration + + + + + Param + + + Type + + + Required + + + Options (default first) + + + Description + + + + + + el + string + Yes + + Identifier of the HTML element to render the chart in your web page + + + url + string + Yes + + Base URL of the DHIS server + + + id + string + No + + Identifier of a pre-defined chart (favorite) in DHIS + + + mapViews + array + Yes (if no id provided) + + Array of layers + + + +
+ + If no id is provided you must add map view objects with the following config options: + + + + + + layer + string + No + "thematic1" | "thematic2" | "thematic3" | "thematic4" | "boundary" | "facility" | + The layer to which the map view content should be added + + + columns + array + Yes + + Indicator, data element, data operand or data set (only one will be used) + + + rows + array + Yes + + Organisation units (multiple allowed) + + + filter + array + Yes + + Period (only one will be used) + + + classes + integer + No + 5 | 1-7 + The number of automatic legend classes + + + method + integer + No + 2 | 3 + Legend calculation method where 2 = equal intervals and 3 = equal counts + + + colorLow + string + No + "ff0000" (red) | Any hex color + The color representing the first automatic legend class + + + colorHigh + string + No + "00ff00" (green) | Any hex color + The color representing the last automatic legend class + + + radiusLow + integer + No + 5 | Any integer + Only applies for facilities (points) - radius of the point with lowest value + + + radiusHigh + integer + No + 15 | Any integer + Only applies for facilities (points) - radius of the point with highest value + + + opacity + double + No + 0.8 | 0 - 1 + Opacity/transparency of the layer content + + + legendSet + object + No + + Pre-defined legend set. Will override the automatic legend set. + + + width + integer + No + + Width of map + + + height + integer + No + + Height of map + + + +
+ We continue by adding one pre-defined and one dynamically configured map to our HTML document. You can browse the list of available maps using the Web API here: . + function setLinks() { + Ext.onReady(function() { + var url = "http://apps.dhis2.org/demo/"; + + GIS.plugin.getMap({ + url: url, + el: "mapA1", + id: "ytkZY3ChM6J" + }); + + GIS.plugin.getMap({ + url: url, + el: "mapB1", + mapViews: [{ + columns: [{dimension: 'in', items: [{id: 'Uvn6LCg7dVU'}]}], // data + rows: [{dimension: 'ou', items: [{id: 'LEVEL-3'}, {id: 'ImspTQPwCqd'}]}], // organisation units + filters: [{dimension: 'pe', items: [{id: 'LAST_3_MONTHS'}]}], // period + classes: 7, + colorLow: '02079c', + colorHigh: 'e5ecff', + opacity: 0.9 + //legendSet: {id: 'fqs276KXCXi'} + }] + }); + }); + }; + Finally we include some div elements in the body section of the HTML document with the identifiers referred to in the plug-in Javascript. + <div id="mapA1" class="chart"></div> + <div id="mapB1" class="chart"></div> + + To see a complete working example please visit . +
+ + + + + + + + +
Creating a chart carousel with the carousel plug-in The chart plug-in also makes it possible to create a chart carousel which for instance can be used to create an attractive front page on a Web portal. To use the carousel we need to import a few files in the head section of our HTML page: