XQuery/Google Charts

Motivation
You want a XQuery function to create charts using the Google Chart API service.

Method
We will create a simple XQuery function that takes the required parameters of a Google Chart (i.e. chart data, size, colors, and labels). It will then construct a URL with the correct values. You can then embed this URL in your XQuery to display the chart.

URL Encoded Parameters
Google Charts uses URL parameters to encode the values for charts like |Jan|Feb|Mar|Apl|May|Jun|1:|10|50|100&chxr=0,-5,100&chxt=x,r&chbh=a&chs=300x150&cht=bvs&chco=0000FF&chd=t:10,20,30,40,50,60&chp=0.05&chtt=Downloads+Per+Month this one. Here is a clearer rendering of the URL parameters for the chart:

http://chart.apis.google.com/chart? chxl=0:|Jan|Feb|Mar|Apl|May|Jun|1:|10|50|100 &chxr=0,-5,100 &chxt=x,r &chbh=a &chs=300x150 &cht=bvs &chco=0000FF &chd=t:10,20,30,40,50,60 &chp=0.05 &chtt=Downloads+Per+Month

Source Code
Here is an example function:

Checking for required parameters
The following adds a fuller set of Google Chart parameters, and gives each parameter a @required attribute:

Acknowledgments
Fraser Hore and Dmitriy Shabanov posted these examples to the eXist mailing list.

Resources
Sample XML Schema for checking Google Chart Parameters