Bad spacing of time series x axis

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

Bad spacing of time series x axis

Post by Anthony Berglas » Thu Mar 07, 2002 4:10 am

Hello,

I am creating a time series chart for a series of points that extend
over a week. The result is output to a .png file for static display on a web page. The time series is in Milliseconds to avoid GMT issues.


The problem is that I only get a very few dates on the x-axis, even
though there appears to be space for many more. Surprisingly, making
the graph wider seems to resolve the problem by making the dates
closer togather, and more numerous. Obviously a bug in the space
allocation part of JFreeChart.
indirection!

An example can be seen at http://www.geocities.com/aberglas/index.html

Does anyone know what the key routines for spacing out the labels is?
I spent some time reading through the code but got lost after umpteen
levels of indirection.

Our basic code looks like:-

TimeSeriesCollection plotData = new TimeSeriesCollection();

plotData.addSeries(createMeasurementTimeSeries());

JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, plotData, true);

Plot plot = chart.getPlot();

ChartUtilities.saveChartAsPNG(file, chart, 500, 300);

Where createMeasurementTimeSeries returns
ts = BasicTimeSeries(, Millisecond.class)
after many ts.add(new Millisecond(...), value);

Thanks,

Anthony

David Gilbert

Re: Bad spacing of time series x axis

Post by David Gilbert » Thu Mar 07, 2002 8:00 am

Hi Anthony,

The auto tick unit selection code is probably the most complex code in JFreeChart. I've rewritten it for the NumberAxis classes. On my to-do list is to do the same for the DateAxis classes.

One thing you could try...at the bottom of the DateAxis.java file there are three arrays containing data for the standard tick units. Add an extra item in each array between the 1 and 7 day units. You can have as many items as you want as long as all three arrays have corresponding items and remain in ascending order.

Regards,

DG.

Jim McLaughlin

Re: Bad spacing of time series x axis

Post by Jim McLaughlin » Fri Mar 08, 2002 6:36 pm

Also, try setting the TickLabels to vertical for the HorizontalDateAxis to get more labels in:

final HorizontalDateAxis hdax = (HorizontalDateAxis) plot.getHorizontalAxis ();
hdax.setVerticalTickLabels (true);

I also had good success subclassing DateUnit to create my own scaling (applause to the JFreeChart developers for a well thought out design). Just make sure you call

hdax.setAutoTickUnitSelection (false);

if you choose to do this.

hth,
Jim McLaughlin

Locked