Horizontal axis not lined up

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

Horizontal axis not lined up

Post by Jason Brawner » Mon Apr 08, 2002 10:00 pm

Hi,

I'm using a time series chart with dates along the horizontal axis and numbers on the vertical. My chart does show the grid so its easy to match up a date with its respective number value.

My problem is that each date plotted on the graph is exactly inbetween two dates, not on the grid as expected. For example, when showing a value for April 8, 2002 the value is drawn exatly between April 8 and April 9. How do I fix this?

Thanks in advance for your help.

JEB

David Gilbert

Re: Horizontal axis not lined up

Post by David Gilbert » Mon Apr 08, 2002 10:22 pm

Hi Jason,

It's something that I'm looking at. The ticks on the axis are being drawn at the start of each unit (day, year, whatever) while the datavalues are being plotted in the middle of each tick unit. The quick fix would be to change the getXValue method in the TimeSeriesCollection method to return the start value rather than the middle value for the time period...but I'm going to try to find a more general solution.

Regards,

DG.

Leo

Re: Horizontal axis not lined up

Post by Leo » Mon Apr 29, 2002 6:27 pm

So how's the status of this problem/feature?
Is there any workaround?
Thanks.

David Gilbert

Re: Horizontal axis not lined up

Post by David Gilbert » Mon Apr 29, 2002 6:58 pm

I haven't started any work on it yet...but I haven't forgotten it, I'm just busy on other things right now.

The easiest workaround is to modify the getXValue method in the TimeSeriesCollection class, as mentioned.

Regards,

DG.

Ferenc Papai

Grid lines not lined up with date units

Post by Ferenc Papai » Wed May 01, 2002 8:50 pm

Hi

The above mentioned problem occured for me too.
My problem is that I am drawing the grid lines along the horizontal axis on weekly based units. and the grid lines fall on the middle of the week, wendsday. This is a bit confusing.

I tried to change the code in TimeSeriesCollection.getXValue method but it had no effect.


the axis set up code
...
HorizontalDateAxis timeAxis = new HorizontalDateAxis ("Date");
timeAxis.setAutoTickUnitSelection (false);
timeAxis.setTickUnit (new DateUnit (java.util.Calendar.DATE, 7));
...

thanks you

David Gilbert

Re: Grid lines not lined up with date units

Post by David Gilbert » Thu May 02, 2002 6:31 am

I think this is a slightly different problem. The axis has no concept of what a week is, only that you have specified ticks every seven days. So it draws a tick/gridline at the first day on the axis then skips forward 7 days and draws another. I think with a different set of data you might find the gridlines fall on a different day of the week.

If I can think of a fix, what day of the week do you want as the default (Monday?).

Regards,

DG.

Ferenc Papai

grid lines not lined up..

Post by Ferenc Papai » Thu May 02, 2002 2:27 pm

Thanks for you quick reply !!!!

Yes, I think the grid line should be drawn between the end and the beginning of the unit given be the user. In my example, between the day 6 (sunday) and day 0 (monday). But this should work even for other time units like 12 days, 2 month, years, minutes..

For me it feels more real that grid lines should separate the units, not be in the middle or in other part of it. True, there might some cases where somebody would like the grid line in the middle part of the given unit. Would it be difficult to customise this ?
I imagine something like this:

axis.setGridPosition (float pos);

where pos is from 0...1, signalling the beginning=0, end=1, or the middle=0.5 of the given unit.

I would happy to hack some code, just is so diffcult to stat with it. Is there maybe some publicly available developer information?

thanks again
Feri

Martin Smith

Re: Grid lines not lined up with date units

Post by Martin Smith » Fri May 03, 2002 10:20 pm

It appears that a workaround solution is to have the getEnd getMiddle and getStart methods all return the same date ( i.e. the start date). Just setting getMiddle to getStart() does not cause the data to plot on the grid line. I found this out when working on my own TimePeriod class. Unless I have all three methods return the same date the data points are drawn in the middle of the date period.

Martin Smith

Locked