How to Fix the Range Axis in TimeSeries Graph

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

How to Fix the Range Axis in TimeSeries Graph

Post by Ratnakar Malla » Wed Nov 06, 2002 5:07 am

Hi All,

I am trying to draw a basic Time series graph. I would like to plot
monthly data. However I observed that , if the size of the graph
is increased , the graph range breakdowns to every 15 days.
How can I fix the range so that it always displays months , and
not 15 days or something else.

Eg:

I want the X-Axis to show range as
Jan 2001, Feb 2001, Mar 2001 .....

But now, sometimes i get

Jan 1 , Jan 16 , Mar 2 , .....

I am constructing BasicTimeSeries Object like this:

BasicTimeSeries t1 = new BasicTimeSeries("Annual", "Year", "Value", Month.class);

As you see, I am explicitly stating that data is monthly.


Can you please help me?

Cheers
-Ratnakar

Dave Gilbert

Re: How to Fix the Range Axis in TimeSeries Graph

Post by Dave Gilbert » Wed Nov 06, 2002 6:35 pm

The tick units used on the axis are not guaranteed to match the intervals in your dataset. In fact, via the XYDataset interface (which is all that XYPlot relies on most of the time), there is no easy way to find out what the intervals are in your data. Furthermore, your data doesn't even have to have regular intervals.

Aside from that, you can "fix" the tick unit on your axis using the setTickUnit(...) method:

XYPlot plot = myChart.getXYPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
DateTickUnit unit = new DateTickUnit(DateTickUnit.MONTH, 1);
axis.setTickUnit(unit);

The only thing you need to watch out for after doing that, is that the tick labels might overlap if you resize the chart.

Regards,

DG.

Ratnakar

Re: How to Fix the Range Axis in TimeSeries Graph

Post by Ratnakar » Wed Nov 06, 2002 9:15 pm

Thanx Dave that helped.
I dont think the overlap of labels should be any problem, as I am using
JFreeChart in a servlet Context, and once an image is generated, there is
no resize issue.

Cheers,
Ratnakar

Locked