- 1. Chart Processor
- 1.1. Introduction
- 1.2. Chart Input
- 1.3. Displaying the Chart
- 2. Excel Processors
- 2.1. Preparing the Spreadsheet
- 2.2. Export
- 2.3. Import
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
OPS User Guide
|
Charts and Spreadsheets
1. Chart Processor1.1. IntroductionOPS uses the JFreeChart to draw and display charts. The following features are supported:
A chart consists of two axes. The horizontal (X) axis is called the category axis. The vertical (Y) axis is called the value axis. The chart contains one or more values. Each value is a list of number to be charted. A value entry contains two lists:
data
input. These expressions must return a node set, and every
expression must return a node set of the same length.
1.2. Chart Input
The
Note
The colors are always specified in RGB format, prefixed by a
#. For instance, #FF0000 is a pure red.
The full RelaxNG schema is shown below:
<grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <ref name="chart"/> </start> <define name="chart"> <element name="chart"> <interleave> <element name="type"> <choice> <value>vertical-bar</value> <value>horizontal-bar</value> <value>vertical-bar-3d</value> <value>horizontal-bar-3d</value> <value>stacked-vertical-bar</value> <value>stacked-horizontal-bar</value> <value>stacked-vertical-bar-3d</value> <value>stacked-horizontal-bar-3d</value> <value>line</value> <value>area</value> <value>pie</value> <value>pie-3d</value> </choice> </element> <element name="title"> <data type="string"/> </element> <optional> <element name="map"> <data type="string"/> </element> </optional> <optional> <element name="category-title"> <data type="string"/> </element> </optional> <optional> <element name="category-margin"> <data type="double"/> </element> </optional> <optional> <element name="serie-title"> <data type="string"/> </element> </optional> <oneOrMore> <element name="value"> <attribute name="title"/> <attribute name="categories"/> <attribute name="series"/> <optional> <attribute name="colors"/> </optional> <optional> <attribute name="exploded-percents"/> </optional> <optional> <attribute name="color"> <ref name="color"/> </attribute> </optional> <empty/> </element> </oneOrMore> <element name="x-size"> <data type="integer"/> </element> <element name="y-size"> <data type="integer"/> </element> <optional> <element name="background-color"> <ref name="color"/> </element> </optional> <optional> <element name="title-color"> <ref name="color"/> </element> </optional> <optional> <element name="bar-margin"> <data type="double"/> </element> </optional> <optional> <element name="tick-unit"> <data type="double"/> </element> </optional> <optional> <element name="category-label-angle"> <data type="positiveInteger"/> </element> </optional> <optional> <element name="legend"> <optional> <attribute name="visible"> <data type="boolean"/> </attribute> </optional> <optional> <attribute name="position"> <choice> <value>north</value> <value>east</value> <value>south</value> <value>west</value> </choice> </attribute> </optional> <zeroOrMore> <element name="item"> <attribute name="color"> <ref name="color"/> </attribute> <attribute name="label"> <data type="string"/> </attribute> <empty/> </element> </zeroOrMore> </element> </optional> </interleave> </element> </define> <define name="color"> <data type="string"> <param name="pattern">#[0-9A-Fa-f]{6}</param> </data> </define> </grammar>
1.3. Displaying the Chart
The Chart Serializer outputs an XML document on its
<chart-info> <file>jfreechart-20234.png</file> <map name="fruits"> <area shape="RECT" coords="66,54,86,235" title="May, Apples = 10"/> <area shape="RECT" coords="93,35,113,234" title="June, Apples = 11"/> <area shape="RECT" coords="131,72,151,235" title="May, Oranges = 9"/> <area shape="RECT" coords="158,90,178,235" title="June, Oranges = 8"/> <area shape="RECT" coords="196,90,216,235" title="May, Bananas = 8"/> <area shape="RECT" coords="223,126,243,235" title="June, Bananas = 6"/> <area shape="RECT" coords="261,108,281,235" title="May, Berries = 7"/> <area shape="RECT" coords="289,54,309,235" title="June, Berries = 10"/> <area shape="RECT" coords="326,126,346,235" title="May, Pears = 6"/> <area shape="RECT" coords="354,163,374,235" title="June, Pears = 4"/> </map> </chart-info>
You need to setup a special servlet in your Web application
descriptor (web.xml) to serve the chart image file. The
following line declares the servlet and maps it to
<servlet> <servlet-name>DisplayChart</servlet-name> <servlet-class>com.jrefinery.chart.servlet.DisplayChart</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>DisplayChart</servlet-name> <url-pattern>/chartDisplay</url-pattern> </servlet-mapping>
The following XSLT template can be used to extract the chart information and generate HTML:
<xsl:template match="chart-info" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <img src="chartDisplay?filename={file}" usemap="#fruits" border="0" width="400" height="300"/> <xsl:copy-of select="map"/> </xsl:template>
2. Excel ProcessorsNote
These processors are deprecated. Please refer to the Converters section for up-to-date information. OPS ships with the POI library which allows import and export of Microsoft Excel documents. OPS uses an Excel file template to define the layout of the spreadsheet. You define cells that will contain the values with a special markup. 2.1. Preparing the Spreadsheet
First, create an Excel spreadsheet with the formatting of your choosing.
Values are taken from the
2.2. Export
The XLS Serializer processor takes a
<p:processor name="oxf:xls-serializer" xmlns:p="http://www.orbeon.com/oxf/pipeline"> <p:input name="config"> <config template="oxf:/excel/template.xls" filename="currency.xls"/> </p:input> <p:input name="data"> <currency> <value1>10</value1> <value2>20</value2> <value3>30</value3> </currency> </p:input> </p:processor>
2.3. Import
The XLS Generator works in a similar way. It typically takes a file uploaded by
a user, finds the special markup cells and reconstructs an XML document. The
generator has one input
<form action="excel/import" method="post" enctype="multipart/form-data"> <input type="file" name="xls"/> <input type="submit" value="Import"/> </form>
The XPL pipeline can then instantiate the XLS Generator with the following:
<p:processor name="oxf:xls-generator" xmlns:p="http://www.orbeon.com/oxf/pipeline"> <p:input name="request" href="#request"/> <p:output name="data" id="xls"/> </p:processor>
|