Align DateTicks to a specific date

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
fhaselbein
Posts: 6
Joined: Tue Oct 16, 2007 3:42 pm

Align DateTicks to a specific date

Post by fhaselbein » Wed Nov 07, 2007 1:30 pm

Hi,

I have a chart that could be displayed in various time lengths (e.g. 1 day, 1 week, 1 month etc).
I'm using

Code: Select all

		switch((int)(length / 3600)) //length in hours
		{
		case 1: return new DateTickUnit(DateTickUnit.MINUTE, 15);
		case 6: return new DateTickUnit(DateTickUnit.HOUR, 1);
		case 24: return new DateTickUnit(DateTickUnit.HOUR, 4);
		case 24 * 7: return new DateTickUnit(DateTickUnit.DAY, 1);
		case 24 * 30: return new DateTickUnit(DateTickUnit.DAY, 7);
		case 24 * 120: return new DateTickUnit(DateTickUnit.MONTH, 1);
		//1 yr won't be changed
		default: return null;
		}
But when I use the DateTickUnit.HOUR, .MINUTE or .DAY, the tick is aligned to the wrong time, e.g. to 23:00 instead of 24:00 (00:00). I checked out the sourcecode of DateAxis and found in previousStandardDate(..), where the calculation of the first used date/time is done, that in the switch (unit.getUnit()), there is e.g. in DAY standing:

Code: Select all

                Date d2 = calendar.getTime();
                if (d2.getTime() >= date.getTime()) {
                    calendar.set(Calendar.DATE, value - 1);
                    d2 = calendar.getTime();
                }
                return d2;
what for is this code, why is 1 substracted? I commented it out and now it works fine. Maybe the >= is wrong and it should be > only? Because in my cases, the d2 and date were equal everytime.

Or is there any other possibility to set the start date/time of the ticks to some value? Note that actually with having the lines commented out it seems to work fine.

Thanks Bye Michael

Locked