XForms/Google Charts

Motivation
You want to use a web service to create charts.

Method
In this example we will use the Google Chart web service: *. Users are each allowed to generate up to 50,000 charts per day.

Parameters
The Google Chart application takes several parameters from the URL. For a simple Pie Chart these might include:

http://chart.apis.google.com/chart? cht=p &chd=t:10,20,30,40,20 &chl=Amount|Indicator|Code|Date|Text &chs=400x300

Where:

- is the Chart API's base URL The ampersand (&) separates parameters. is a code for the chart's type. For example p=2D Pie Chart and p3-3D Pie Chart is the chart's data using t format (t:10,20,30) or s format where (s:) a=1 and z=26 - is the chart's size in pixels. =Amount|Indicator|Code|Date|Text are the labels for the Pie Chart.

Our next step is to put these REST parameters into an XForms instance and hook the instance up to input controls.

Pie Chart Parameters in XML instance
Here are the parameters for a piechart type, data, label and size information.



Chart Submission
We will submit our XForms data to the server using the following submission statement.

Binding Rules
Here is a sample input form for chart parameters:

Here is a sample output chart generated form this application.

Sample XForms Application on Google Code
Execute

Sample Program
      Google PieChart Demo

 Chart Type:   Pie Chart - flat p  <xf:item> <xf:label>Pie Chart - 3D</xf:label> <xf:value>p3</xf:value> </xf:item> </xf:select1> <xf:input ref="chd"> <xf:label>Data: (t:5,10,20): </xf:label> </xf:input> <xf:input ref="chl"> <xf:label>Labels: (A|B) </xf:label> </xf:input> <xf:submit submission="get-chart"> <xf:label>Create Chart</xf:label> </xf:submit>

Discussion
This is actually one of the most simple applications. Google Charts has five chart types and hundreds of combinations of parameters. The Chart Types are (cht)


 * 1) Line charts
 * 2) Bar charts
 * 3) Pie charts
 * 4) Venn diagrams
 * 5) Scatter plots

One way to test these is to generate a variety of charts with some sample XForms.