Sunday, June 17, 2007

Charting the web with Cewolf/JFreeChart - Producing Time Series plots

I recently had an opportunity to use the Cewolf 1.0 at work for some Time Series plots (a variant of the XY Chart, shown in the figure above, where the X-axis is for time values). This blog is about Cewolf and how to create time series plots with it.

Cewolf is a JSP tag library which uses JFreeChart for rendering the charts. It comes with a controller servlet which is used for interpreting the parameters passed through the JSP tag and accordingly generating the chart image in-memory (no files created on the file system of the server) and embeds the image as tag in the HTML output to the client response stream.

IMO, Cewolf/JFreeChart is the best free charting package for a web application required to draw charts and being developed in Java EE. It supports several different types of charts and one of them was the Time Series plots. Here is some code which can produce a simple time series plot (using cewolf).

1. To install Cewolf you just need to copy the jars from its lib/ path (which includes the JFreeChart jar too) to WEB-INF/lib of your web application.

2. We need to write a data producer which gets the data set (in {time, value} pairs for the time series plot). A typical time series data producer is given below:

//~--- non-JDK imports --------------------------------------------------------

import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;


//~--- JDK imports ------------------------------------------------------------


import java.util.Date;
import java.util.Map;

* A sample data producer for the time series plot.
public class MyDataProducer implements DatasetProducer, Serializable
public MyDataProducer()

public Object produceDataset(Map map) throws DatasetProduceException
* To this time series collection we can add more than one time series
* where each time series will be represented by its own line on a
* plot.
TimeSeriesCollection ts = new TimeSeriesCollection();

try {
String[] allSeries = { "series1", "series2" };

// Loop through all series and add the data to series and series to
// timeseries collection (ts).
for (int i = 0; i < allSeries.length; i++) {

// Get data for series from some kind of datasource
MyDataSet[] myDataSet = GetDataForSeries(allSeries[i]);
TimeSeries mySeries = new TimeSeries("My Data Series " + i, Minute.class);

// Add data to series
for (MyDataSet data : myDataSet) {
mySeries.add(new Minute(new Date(data.getTimestamp().getTime())), data.getYValue());

// Add the series to the collection
} catch (Exception e) {

throw new DatasetProduceException();

return ts;

public boolean hasExpired(Map map, Date date)
return false;

public String getProducerId()
return "My Data Producer";

private MyDataSet[] GetDataForSeries(String string)
// Get data from DB or some data source
// return an array of time/value pairs (for instance, as an array
// of MyDataSet instances.

MyDataSet class is:

import java.sql.Timestamp;

/** A sample time/value pair data. An array/list of this type will constitute
* the data set for the plot.
public class MyDataSet
private Timestamp timestamp; // You can use other date/time types in Java SE here.
private double yValue;

public MyDataSet()

public Timestamp getTimestamp() {
return timestamp;

public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;

public double getYValue() {
return yValue;

public void setYValue(double yValue) {
this.yValue = yValue;

In the JSP page you include the chart now:

<jsp:usebean id="myPlotData" class="com.mycompany.MyDataProducer">

title="My Plot Title"
yaxislabel="My Data Value">
<cewolf:producer id="myPlotData" usecache="false">
<cewolf:img chartid="MyChart" renderer="/cewolf" width="1000" height="400">

Lastly, one needs to configure the CewolfServlet in the web.xml:


The generated charts on tomcat does require one to increase the JVM heap size to at least 256MB from the default 64MB.

The pros of using Cewolf/JFreeChart in a Java EE web application:
1. Compared to the other open source packages, JFreeChart happens to be the best in terms of the look and feel of the plots and the ease of use of the API.
2. Cewolf contributes to the glory by making the JFreeChart available as JSP tag library. And as far as i know, there isn't any other better option for plotting in the open source Java world.

The duo of Cewolf/JFreeChart are lacking in a few important features:
1. AJAX support for real-time plots. So if we want the server to be able to asynchronously (or by the virtue of some background polling from client) refresh the chart in (near) real-time then its not something supported today in Cewolf/JFreeChart. If this feature is required then JViews Charts or Chart Director are the two commercial offerings that i know of that can do AJAX based live charts.
2. Zoom and Pan interactions are not easily supported by the API.


Anonymous said...

Gauche! You lack conitnuity man.

Anonymous said...


Is there a way to pass data to the constructor of the DataProducer Class, how do we pass parameters to teh consturctor from a JSP?

Anonymous said...

We can't pass any parameter to the constructor of the DataProducer Class. But we can pass the parameters map to the method which is producing Dataset object (public Object produceDataset(Map params))
On the JSP page you mast use cewolf:param tag inside cewolf:producer tag with attributes name (indicate the key in passed to the method map) and value (indicate the value in map).

In method produceDataset you can get parameter by name (the same as value of name attribute in cewolf:param tag) from map.

Anonymous said...

Making gw gold is the old question : Honestly there is no fast way to make lots of GuildWars Gold . Sadly enough a lot of the people that all of a sudden come to with millions of Guild Wars Gold almost overnight probably duped . Although there are a lot of ways to make lots of GuildWars moneyhere I will tell you all of the ways that I know and what I do to make cheap gw gold.

As a new player , you may need some game guides or information to enhance yourself.
habbo credits is one of the hardest theme for every class at the beginning . You must have a good way to manage yourhabbo gold.If yor are a lucky guy ,you can earn so many habbo coins by yourself . But if you are a not , I just find a nice way to get buy habbo gold. If you need , you can buycheap habbo credits at our website . Go to the related page and check the detailed information . Once you have any question , you can connect our customer service at any time .

Anonymous said...

aion chinaaion china gold,
aion cn goldaion chinese gold,
aion gold chinaaion gold chinese,
china aion goldchinese aion gold,
aion china kinaaion chinese kina,
aion kina chinachina aion kina,
aion china buybuy aion china,
aion chinese server

aion cn server

aion china server goldchina aion server gold,
chinese aion server

aion chinese server

aion cn server kinaaion china server kina,
china aion server kinachinese aion server kina

15 sorting algorithms visualized in 5 minutes, with awesome arcade sounds

15 sorting algorithms visualized in 5 minutes, with awesome arcade sounds from r/programming