GeoServer chart extension

Business reporting is a common need in various organisations. Most of the time, it is built upon tables and simple charts, such as pie or bar charts. Yet, sometimes, you need to add an extra dimension into it, in particular, geographic distribution. In some cases a thematic map does the job nicely, but if you need to represent the composition of a phenomena relying on more than one variable, the result ends up being hard to read.

This is where the overlay of charts and maps come into play: the idea is to overlay bar chars, or pie charts, over a polygon or point map, associating each geographic feature with its own little diagram. As surprising as it may sound, you have been able to create such maps with GeoServer since a few months ago: by putting together the dynamic symbolizers feature and the Google Charts online API, it’s already possible to nicely overlay charts of top of a map. This works great in conjuction with the KML output, where the client has to go and fetch the chart separately anyways. However, it present some limitations in the classic WMS case:

  • you are depending on an external service that’s not under your control
  • if there is any missing feature, you can just ask and hope that next release will include that feature
  • rendering the charts requires remote calls, which will slow down the map rendering significantly, at least for the first requests

An open source solution, completely embedded in GeoServer, would guarantee control over the service availability, over its features, and provide excellent performance. David Gilbert, of JFreeChart fame, must have thought the same when he developed Eastwood Charts, an open source implementation of the Google Charts API.

The GeoServer charting module builds on top of Eastwood charts, bridging it with the dynamic symbolizers capabilities already available, to provide fast, in process charting over the map. Let’s have a look at an example built on top of the usual topp:states demo layer. We are going to depict the distribution of male/female population in the various states using pie charts, and to make the diagram more interesting, we’ll make the pie size proportional to the total amount of people in the state. Here is how the result will look:

You can download the full style if you like, here we’ll have a look at the snippet in which the diagram is setup:

        <OnlineResource xlink:href="http://chart?cht=p&chd=t:${100 * MALE / PERSONS},${100 * FEMALE / PERSONS}&chf=bg,s,FFFFFF00" />

Let’s analyse the components of the ExternalGraphic call, which follow the rules of a Google Charts API call:

  • cht=p: the chart type is pie
  • chd=t:${100 * MALE / PERSONS},${100 * FEMALE / PERSONS}: the chart data is expressed in “text” format, and in particular, the first value is the result of 100 * MALE / PERSONS, where MALE and PERSONS are two attributes of feature being rendered
  • chf=bg,s,FFFFFF00: we state that the chart background fill is solid, white and… transparent. In particular, the color is expressed as RRGGBBAA, where AA is the alpha component, which controls transparency. In particular 0 is fully transparent, 255 is fully opaque

The size of the chart is controlled using the usual <Size> element of external graphics, an in particular, it’s setup so that it’s proportional to the PERSONS attribute via the expression: 20 + (PERSONS / 20,000,000) * 60.

We encourage you to download the chart extension and to explore its charting possibilities. You can use it with GeoServer 1.7.4, and can find out more about chart setup in the online Google Charts documentation (mind, a handful of charts and options are not supported by Eastwood, in particular, the Google-o-meter and the spider ones).

Let us know how that works for you!


  1. Martin
    Posted June 1, 2009 at 1:48 pm | Permalink

    This is great!
    The link to the charting extension refers to the sld file. Can’t find the extension on

    Am i doing anythuing wrong ?

  2. Andrea Aime
    Posted June 1, 2009 at 1:57 pm | Permalink

    Martin, sorry, the links was incorrect, I fixed it.

  3. Posted June 5, 2009 at 11:02 am | Permalink

    This looks really interesting, but I’m afraid us n00bs need a bit of documentation on how to actually use it. I have downloaded it and added into the lib folder as usual, but I’m not sure how to take it any further.

    BTW, I’ve always thought it would be really handy if the admin section of the geoserver interface could show you which extensions are active!



  4. Santiago
    Posted June 15, 2009 at 3:04 pm | Permalink

    Hi, i add the jar files into the lib file but it seems to be the wrong path because the charts doesnt appear and in the console shows the following log:

    15 jun 16:53:47 WARN [geotools.factory] – Error en la inicialización de un servicio de categoría “ExternalGraphicFactory”. La causa es “NoClassDefFoundError: org/geotools/renderer/style/ExternalGraphicFactory”.
    15 jun 16:53:47 ERROR [shape.StyledShapePainter] – ShapePainter has been asked to paint a null style!!
    15 jun 16:53:47 ERROR [shape.StyledShapePainter] – ShapePainter has been asked to paint a null style!!

    Where is the correct place to put the jar files?

    Thanks, Santiago.

  5. Andrea Aime
    Posted June 16, 2009 at 2:25 am | Permalink

    Hi Santiago,
    I’ve answered your question on the mailing list—td24042080.html

  6. Sareuon
    Posted September 9, 2009 at 2:03 am | Permalink

    Hi, I have a problem when I going to create new style by passing the style about I got an error :

    NVALID XML: The reference to entity “chd” must end with the ‘;’ delimiter

    I think because of the line:

  7. Barre
    Posted November 8, 2009 at 4:04 am | Permalink

    For solve the “reference to entity “chd” must end with the ‘;’ delimiter” problem, just replace all the & with an & amp; (without the space) in the command href=…

Download GeoServer