Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

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:

http://chart.apis.google.com/chart? - is the Chart API's base URL

The ampersand (&) separates parameters.

cht=p is a code for the chart's type. For example p=2D Pie Chart and p3-3D Pie Chart

chd=t:10,20,30,40 is the chart's data using t format (t:10,20,30) or s format where (s:) a=1 and z=26

chs=400x300 - is the chart's size in pixels.

chl=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.

id="chart-params" xmlns="">

Chart Submission

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

id="get-chart"
method="get" action="http://chart.apis.google.com/chart"
separator="&" ref="instance('chart-params')" replace="all"/>

Binding Rules

Here is a sample input form for chart parameters:

Input to Chart Generated by Google Charts (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)

Here is a sample output chart generated form this application.

Chart Generate by Google Charts (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)

Sample XForms Application on Google Code

Execute

Sample Program

<html xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Pie Chart Demo</title>
<style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family: Helvetica, sans-serif}

/* This line ensures all the separate input controls appear on their own lines */
xf|input, xf|select1 {display:block; margin:5px 0;}

/* this puts the labels in 200px columns and right aligns them */
xf|input > xf|label, xf|select1 > xf|label
{text-align:right; padding-right:10px; width:200px; float:left; text-align:right;}

.xf-value {width: 250px}
</style>
<xf:model>
<xf:instance id="chart-params" xmlns="">
<data>
<cht>p</cht>
<chs>400x200</chs>
<chd>t:1,2,60,40,2</chd>
<chl>Amount|Indicators|Code|D|Text</chl>
</data>
</xf:instance>

<xf:submission id="get-chart" action="http://chart.apis.google.com/chart" method="get"
separator="&" ref="instance('chart-params')" replace="all"/>

<xf:action ev:event="xforms-ready">
<xf:setfocus control="field-1"/>
</xf:action>
</xf:model>
</head>
<body>
<h3>Google PieChart Demo</h3>

<xf:select1 ref="cht" id="field-1">
<xf:label>Chart Type: </xf:label>
<xf:item>
<xf:label>Pie Chart - flat</xf:label>
<xf:value>p</xf:value>
</xf:item>
<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>

</body>
</html>

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)

  • Line charts
  • Bar charts
  • Pie charts
  • Venn diagrams
  • Scatter plots

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

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
Sending a **submit** will alter the Venn Diagram REST parameters. ### Screen Image of User Interface ![XForms User Interface for Venn Diagram]( XForms User Interface for Venn Diagram (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0) ### Output of Call to Google Charts
CC BY-SA 4.0
I also need to use CSS to clean up the markup. Price and Demand P Q Demand Input: Price = 100 Output: Quantity = 100 Adjust price by moving the slider. Note that as the input (price) changes. the quantity sold also changes.
CC BY-SA 4.0
This is an example of a self-referential data structure. This is common when manipulating graphs. Workflow systems frequently use these structures. ## Link to Working Example [Graph Editor]( ## XML Schema Here is a sample XML Schema with a recursive data type (a data type that includes an instance o
CC BY-SA 4.0
Try this code instead: <html xmlns:xf=" xmlns:ev=" xmlns=" <head> <title>Demo of XForms Event Logging</title> <style type="text/css"> body {font-family: Helvetica, sans-serif;} #log { font-size: 8pt; color: SlateGray; background-color: lavender; border: 1px solid SlateGray; } </style> <xf:model> <xf
CC BY-SA 4.0
In the example above I used a test folder on the localhost: [ xquery version "1.0"; declare namespace exist = " declare namespace system=" declare namespace request=" declare option exist:serialize "method=xml media-type=text/xml indent=yes"; (: replace demo :) let $input := request:get-parameter('i
CC BY-SA 4.0
*/ .inspector xf|input > xf|label, .inspector xf|select > xf|label, .inspector xf|select1 > xf|label, .inspector xf|textarea > xf|label {text-align:right; padding-right:10px; width:200px; float:left; text-align:right;} /* This line ensures all the separate label controls in the inspector appear on t