Time interval on the x-axis

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

Time interval on the x-axis

Post by Craig Tataryn » Fri Apr 26, 2002 3:45 pm

Currently I have a TimeSeries chart which displays dates on the x-axis. I've noticed the JFreeChart seems to kind of "guess" at what time intervals should be displayed (monthly, weekly, etc..) based on the range of data you provide. Is there a way to let my user choose what intervals are to be displayed at runtime? For instance, they may want to see an interval of one week or every 2 weeks; 1 month or every two months, etc...

Thanks,

Craig.

Troy Schrader

Re: Time interval on the x-axis

Post by Troy Schrader » Fri Apr 26, 2002 4:38 pm

Craig,

You'll have to turn off the AutoTickUnit functionality first, then set your own interval using the fields from the Calendar class. You can then format the the tick labels using SimpleDateFormat.

Here's a snippet:

Plot plot = yourChart.getPlot();
HorizontalDateAxis hdAxis = (HorizontalDateAxis) plot.getHorizontalAxis ();
hdAxis.setAutoTickUnitSelection(false);
hdAxis.setTickUnit(new DateUnit(Calendar.MONTH, 2));
SimpleDateFormat sdf = hdAxis.getTickLabelFormatter();
sdf.applyPattern("M/yyyy");

DateUnit allows you to use the following fields from the Calendar class: YEAR, MONTH, DATE/DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND.

Troy

Craig Tataryn

Re: Time interval on the x-axis

Post by Craig Tataryn » Fri Apr 26, 2002 7:22 pm

Thanks! Will give it a try.

Craig.

Locked