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&amp;chl=male|female&amp;chd=t:${100 * male / (male + female)},${100 * female / (male + female)}&amp;chs=200x100&amp;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&amp;key=valu&amp;….”

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.

Supported keys for the chart URL

Key

Description

cht

Chart type - Supported values are:

Value

Resulting type

Data series

p

Pie chart (1 series)

1

p3

3D Pie chart

1

lc

Line chart

n

ls

Sparkline chart

n

lxy

XY Line chart

2n

bhg

Bar chart - Horizontal

n

bhs

Bar chart - Horizontal - Stacked

n

bhs3

Bar chart - Horizontal - 3D

n

bvg

Bar chart - Vertical

n

bvs

Bar chart - Vertical -Stacked

n

bvg3

Bar chart - Vertical - 3D

n

s

Scatter chart

2 (XY) or 3 (XYZ)

dial

Dial chart

special

v

(Venn diagrams not implemented)

chco

Chart color - format is cColor1 ‘,’ cColor2 ‘,’ cColor3 …

chd

Data - can be formatted in 3 ways: simple/text/extended:

  • Format ‘s:’ serie ‘,’ serie ‘,’ …

    Each serie contains characters A..Z,a..z,0..9 with A being the lowest 0.0 and 9 the highest possible value 1.0

  • Format ‘t:’ fValueSerie1 ‘,’ fValueSerie1 ‘,’ … ‘|’ fValueSerie2 ‘,’ …

  • Format ‘e:’ serie ‘,’ serie ‘,’ …

    This is a high-precision variant of s: Each serie contains character pairs A..Z,a..z,0..9, -. with AA being the lowest 0.0 and .. the highest possible value 1.0

Dials have a special syntax: item ‘,’ item ‘,’ …

Items are:

  • Data range: ‘dr=’ fNumber ‘:’ fNumber ‘:’ cColor

  • lower bound: ‘lb=’ fNumber

  • upper bound: ‘ub=’ fNumber

  • minor tick increment: ‘mt=’ fNumber

  • major tick increment: ‘mjt=’ fNumber

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:

  • background color: ‘bgs’ cColor

  • background linear gradient: ‘blg’ fAngle ‘,’ cColor0 ‘,’ f0 ‘,’ cColor1 ‘,’ f1

  • plot color: ‘cs’ cColor

  • plot linear gradient: ‘clg’ fAngle ‘,’ cColor0 ‘,’ f0 ‘,’ cColor1 ‘,’ f1

  • Google Charts linear stripes are not supported

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.