Graphing TimeSeries in AreaChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Kirby Files

Graphing TimeSeries in AreaChart

Post by Kirby Files » Thu Nov 14, 2002 6:20 pm

Folks,

Could someone please advise me how to graph a TimeSeries as anything other than a TimeSeriesChart? Since a standard DefaultXYDataset didn't work with just putting a Date object into the X data, I tried creating a TimeSeriesCollection:

SimpleDateFormat formatter
= new SimpleDateFormat ("MM/dd/yyyy HH:mm");
TimeSeriesCollection oData = new TimeSeriesCollection();
for (int i=0; i<oCategories.length; i++)
{
BasicTimeSeries oSeries = new BasicTimeSeries(oCategories, Class.forName("com.jrefinery.data.Minute"));
for (int j=0; j<oTimes.length; j++)
{
String strValue = (String)(oTimestamps.get(oTimes[j]));
Date oTime = formatter.parse(oTimes[j]);

Double fValue;
if (strValue != null)
fValue = new Double(strValue);
else
fValue = new Double("0");
oSeries.add(new Minute(oTime), fValue);
}
oData.addSeries(oSeries);
}

JFreeChart chart = ChartFactory.createAreaXYChart(
"Intraday LSP Traffic from " + strSource + " to " + strDest,
"Time", "KBps", oData, true);

However, the AreaXYChart still interprets the dates as ctime values, and labels the X access with milliseconds since the Unix epoch.

Please help, or let me know if the TimeSeriesChart is the only one that properly interprets Date or TimeSeries X values.

Thanks,
---
Kirby Files
Software Develper
Masergy Communications

David Gilbert

Re: Graphing TimeSeries in AreaChart

Post by David Gilbert » Fri Nov 15, 2002 4:13 pm

Hi Kirby,

By default, the AreaXYChart is using a HorizontalNumberAxis. You should be able to replace it with a HorizontalDateAxis - the underlying data will remain the same, but the date axis will convert the milliseconds to a date format:

XYPlot plot = myAreaXYChart.getXYPlot();
HorizontalDateAxis axis = new HorizontalDateAxis("Date");
plot.setDomainAxis(axis);

Regards,

DG

Kirby Files

Re: Graphing TimeSeries in AreaChart

Post by Kirby Files » Fri Nov 15, 2002 5:31 pm

Great, that's working fine. Now that I've also discovered that the CombinedXYPlot requires that the subplots have a null DomainAxis, I'm very happy with the output of JFreechart.

BTW, the exception reported (re: incompatible axes) could really be more specific: "error adding subplot: domainAxis must be null" would be more helpful. I kept trying to set the domainAxis on the CombinedXYPlot and its subplots to the same axis type, figuring that there's no way for identical axes to be "incompatible".

Also, I would love to use JdbcXYDataset, but need to be able to execute multiple queries that each *add* series, rather than replacing the existing series. Our statistics are stored by DEVICE, TIMESTAMP, TYPE, VALUE, rather than DEVICE, TIMESTAMP, VALUE1, VALUE2, VALUE3. Building a query that returns all sample types within a single row for such a schema is very inefficient. A simple boolean argument to executeQuery, "replace=false", would work fine.

Thanks,
--kirby

Dave Gilbert

Re: Graphing TimeSeries in AreaChart

Post by Dave Gilbert » Mon Nov 18, 2002 10:36 am

Kirby Files wrote:
> Great, that's working fine. Now that I've also discovered
> that the CombinedXYPlot requires that the subplots have a
> null DomainAxis, I'm very happy with the output of JFreechart.
>
> BTW, the exception reported (re: incompatible axes) could
> really be more specific: "error adding subplot: domainAxis
> must be null" would be more helpful. I kept trying to set
> the domainAxis on the CombinedXYPlot and its subplots to the
> same axis type, figuring that there's no way for identical
> axes to be "incompatible".

Yes, I can do that. It's one of those things that I don't notice, because I know how it works! But I have been caught out before by obscure error messages, so I know where you are coming from.

> Also, I would love to use JdbcXYDataset, but need to be able
> to execute multiple queries that each *add* series, rather
> than replacing the existing series. Our statistics are
> stored by DEVICE, TIMESTAMP, TYPE, VALUE, rather than DEVICE,
> TIMESTAMP, VALUE1, VALUE2, VALUE3. Building a query that
> returns all sample types within a single row for such a
> schema is very inefficient. A simple boolean argument to
> executeQuery, "replace=false", would work fine.

That sounds like a useful option. I didn't write any of this code, so I'm not that familiar with it...if you feel like modifying it and submitting a patch that would be great.

Regards,

DG

Locked