Fixed a bug into iteration, working example for AJAX APIs Playground git-svn-id: http://soc.googlecode.com/svn/wiki@3238 5fae56a1-394a-0410-ba46-5107137fd53f
diff --git a/StatisticsModule.wiki b/StatisticsModule.wiki index bfb467e..aec044c 100644 --- a/StatisticsModule.wiki +++ b/StatisticsModule.wiki
@@ -70,7 +70,7 @@ } }}} -In this way we can iterate through it as (take it as pseudo-JS-code, didn't test it yet): +In this way we can iterate through it as: {{{ var data = new google.visualization.DataTable(); for (var index in json.columns) { @@ -79,12 +79,65 @@ data.addRows(json.rows.length); for (var row_index in json.rows) { for (var column_index in json.rows[row_index].rowdata) { - data.setValue(row_index, column_index, json.rows[row_index].rowdata[column_index]); + data.setValue(parseInt(row_index), parseInt(column_index), json.rows[row_index].rowdata[column_index]); } } }}} +* Working example, cut and paste the following code into [http://code.google.com/apis/ajax/playground/?type=visualization#image_pie_chart AJAX APIs Playground] + +{{{ +function drawVisualization() { + var json = { + "title": "Title of graph", + "columns": [ + { + "type": "string", + "name": "Degree" + }, + { + "type": "number", + "name": "N. Students" + } + ], + "rows": [ + { + "rowdata": [ + "Undergraduate", + 70 + ] + }, + { + "rowdata": [ + "Master", + 60 + ] + }, + { + "rowdata": [ + "PhD", + 30 + ] + } + ] + }; + + var data = new google.visualization.DataTable(); + for (var index in json.columns) { + data.addColumn(json.columns[index].type, json.columns[index].name); + } + + data.addRows(json.rows.length); + for (var row_index in json.rows) { + for (var column_index in json.rows[row_index].rowdata) { + data.setValue(parseInt(row_index), parseInt(column_index), json.rows[row_index].rowdata[column_index]); + } + } + new google.visualization.ImagePieChart(document.getElementById('visualization')).draw(data, null); +} + +}}} ==== Statistics provisional data model ==== {{{ from google.appengine.ext import db