Chart Plugin¶
The gt-chart plugin supports the definition of a Chart as a Mark or ExternalGraphic. This is implemented as a “dynamic symbolizer” using the JFreeChart and Eastwood projects.
References:
Maven:
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-charts</artifactId>
<version>${geotools.version}</version>
</dependency>
Example¶
The following example is taken from test cases:
Here is the example SLD:
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name></Name>
<title></title>
<abstract></abstract>
<UserStyle>
<Name>Pie charts</Name>
<FeatureTypeStyle>
<Rule>
<PointSymbolizer>
<Graphic>
<ExternalGraphic>
<OnlineResource xlink:href="http://chart?cht=p&chl=male|female&chd=t:${100 * male / (male + female)},${100 * female / (male + female)}&chs=200x100&chf=bg,s,FFFFFF00"/>
<Format>application/chart</Format>
</ExternalGraphic>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Configuration¶
Charts are configured by an URL of the form http://chart?key=value&key=value . In an SLD, the URL needs to be XML-encoded, so you’ll end up with xlink:href=”http://chart?key=value&key=valu&….”
Most keys have multiple arguments, whose name encodes the type: f= floating point, i= integer, c = color RRGGBB or RRGGBBAA
The chart plugin implements the URLs using Eastwood, an old and now-abandoned library based on JFreeCharts (last release is 2008). In turn, Eastwood implemented part of the Google Charts API, also now abandoned and replaced by a Javascript library.
The original Google documentation for these keys is thankfully saved in the Wayback Machine. Be patient, it’s slow and sometimes fails with a 500, but if you insist you’ll get to the page. https://web.archive.org/web/20080203131425/https://code.google.com/apis/chart Note how parameters from 2010 onwards are not implemented by this plugin.
The following keys are supported.
Key |
Description |
|||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cht |
Chart type - Supported values are:
|
|||||||||||||||||||||||||||||||||||||||||||||
chco |
Chart color - format is cColor1 ‘,’ cColor2 ‘,’ cColor3 … |
|||||||||||||||||||||||||||||||||||||||||||||
chd |
Data - can be formatted in 3 ways: simple/text/extended:
Dials have a special syntax: item ‘,’ item ‘,’ … Items are:
|
|||||||||||||||||||||||||||||||||||||||||||||
chds |
Data scaling - format is fScale ‘,’ fScale ‘,’ … This is an Eastwood extension, not part of Google Charts. |
|||||||||||||||||||||||||||||||||||||||||||||
chf |
Fill spec - format is spec ‘|’ spec Spec is one of:
|
|||||||||||||||||||||||||||||||||||||||||||||
chg |
Grid line spec - format is fXStep ‘,’ fYStep ‘,’ fLineSegLen ‘, ‘ fBlankSegLen |
|||||||||||||||||||||||||||||||||||||||||||||
chl |
Labels - format is label ‘|’ label … |
|||||||||||||||||||||||||||||||||||||||||||||
chdl |
Legend - format is label ‘|’ label … |
|||||||||||||||||||||||||||||||||||||||||||||
chls |
Line style - format is fWidth ‘,’ fLineRun ‘,’ fGapRun ‘|’ … |
|||||||||||||||||||||||||||||||||||||||||||||
chm |
Markers - format is type ‘,’ cColor ‘,’ (ignored) ‘,’ fStart ‘,’ fEnd ‘|’ … Types are ‘r’ for a range (Y-axis) marker, ‘R’ for a domain (X-axis) marker. Google Chart shape markers are not supported. |
|||||||||||||||||||||||||||||||||||||||||||||
chp |
Pie chart rotation - format is fAngle This is an Eastwood extension, not part of Google Charts. |
|||||||||||||||||||||||||||||||||||||||||||||
chs |
Chart size - format is iWidth ‘x’ iHeight ( in pixels) |
|||||||||||||||||||||||||||||||||||||||||||||
chts |
Axis title style - format is: cTitleColor ‘,’ iFontSize |
|||||||||||||||||||||||||||||||||||||||||||||
chtt |
Axis title - format is title ‘|’ title ‘|’ … |
|||||||||||||||||||||||||||||||||||||||||||||
chxr |
Axis range - format is: iAxisIndex ‘,’ fLowerBound ‘,’ fUpperBound ‘|’ … |
|||||||||||||||||||||||||||||||||||||||||||||
chxl |
Axis label - format is: iAxisIndex ‘:’ sText ‘|’ … |
|||||||||||||||||||||||||||||||||||||||||||||
chxp |
Axis label position - format is: iAxisIndex ‘,’ fTickNumber ‘,’ fTickNumber … ‘|’ … |
|||||||||||||||||||||||||||||||||||||||||||||
chxs |
Axis style - format is: iAxisIndex ‘,’ cAxisColor ‘,’ fFontsize ‘,’ unused ‘,’ drawingcontrol ‘,’ cTickColor ‘|’ … drawingcontrol is an Eastwood extension, not part of Google Charts., ‘l’ /’t’ / ‘_’ / ‘lt’ where l and t make tickmarks and axis line visible. |
|||||||||||||||||||||||||||||||||||||||||||||
chxt |
Axis text - format is: axis ‘,’ axis ‘,’ … axis is one of the characters ‘x’ ‘y’ ‘r’ ‘t’. Every axis defines a new numbered axisindex, starting from 0 |
|||||||||||||||||||||||||||||||||||||||||||||
ewd2 |
Extra dataset, format is the same as chd This is an Eastwood extension, not part of Google Charts. |
|||||||||||||||||||||||||||||||||||||||||||||
ewlo |
Orientations - format is: iAxisIndex ‘,’ orientation ‘|’ … orientation is ‘s’ / ‘u’ / ‘d’ for standard/up/down This is an Eastwood extension, not part of Google Charts. |
|||||||||||||||||||||||||||||||||||||||||||||
ewtr |
format is iSeries ‘,’ cColor ‘,’ cLineWidth This is an Eastwood extension, not part of Google Charts. |