DateAxis tick labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
cirocco
Posts: 4
Joined: Thu Feb 26, 2009 10:14 am

DateAxis tick labels

Post by cirocco » Fri Mar 06, 2009 1:07 pm

Hi
I am using jfreechart 1.0.10, and I have a chart with TimeSeries data.
I am setting
plot.getDomainAxis().setLowerBound(start);
plot.getDomainAxis().setUpperBound(end);
where start is exactly 13:00 and stop is 14:00
tick labels are 13:09 13:19 13:29 13:39 13:49 13:59

I would like them to be more "round" that is 13:20 instead 13:19 and
also 13:00 and 14:00 at start and end.
How to setup this?

jleech
Posts: 62
Joined: Fri Oct 26, 2007 9:18 pm

Re: DateAxis tick labels

Post by jleech » Tue Mar 10, 2009 6:41 pm

JFreeChart tries really hard to make it impossible to both
- Set your own upper and lower bounds
and
- Set the margins (I am guessing you're also setting the margins)
This is because JFreeChart doesn't really have a concept of a margin vs. bounds, it's all the same thing.
You can accept a 0-margin, not set the bounds (you can manafacture data points at the bounds with e.g. Double.NaN values instead),
or you can override JFreeChart's behavior to fix the issue, by overriding the public Date calculateLowestVisibleTickValue(DateTickUnit unit) method of the DateAxis class.

cirocco
Posts: 4
Joined: Thu Feb 26, 2009 10:14 am

Re: DateAxis tick labels

Post by cirocco » Mon Mar 16, 2009 3:03 pm

Thanks, for advice. I did not set the margins.
I have added 1ms to setUpperBound and setLowerBound, and now tick labels are as I wanted.

kasineedis
Posts: 7
Joined: Tue Mar 10, 2009 8:50 pm

DateAxis tick labels

Post by kasineedis » Mon Apr 27, 2009 7:44 pm

Hi
I am using jfreechart 1.0.12, and I have a chart with TimeSeries data.
I am setting
plot.getDomainAxis().setLowerBound(start);
plot.getDomainAxis().setUpperBound(end);
where start is exactly 00:00 and stop is 23:59
tick labels are 00:11 01:11 02:11 03:11 04:11 05:11 06:11 07:11............23:11

I would like them to be more "round" that is 00:00 instead 00:11 ,01:00 instead 01:11 .... etc
Sorry, for asking same kind of question .As they suggested in this forum I alreay used setMargins .Please help
How to setup this?

jleech
Posts: 62
Joined: Fri Oct 26, 2007 9:18 pm

Re: DateAxis tick labels

Post by jleech » Wed Apr 29, 2009 6:20 pm

Like I said before, if you set both the bounds and the margins, you won't get what you want in the values of the tick labels.
To be clear, you can set one or the other, but not both, or you can override the method I mentioned.

kasineedis
Posts: 7
Joined: Tue Mar 10, 2009 8:50 pm

Re: DateAxis tick labels

Post by kasineedis » Thu Apr 30, 2009 3:17 pm

I added the following code .It worked .Thank you very much


domainAxis.setAutoTickUnitSelection(true);
plot.getDomainAxis().setLowerMargin(0.02);
plot.getDomainAxis().setUpperMargin(0.000);
domainAxis.setUpperBound(upper);
domainAxis.setLowerBound(lower);

peetzer
Posts: 11
Joined: Mon May 11, 2009 2:20 pm

Re: DateAxis tick labels

Post by peetzer » Thu May 14, 2009 10:13 am

kasineedis wrote:I added the following code .It worked .Thank you very much


domainAxis.setAutoTickUnitSelection(true);
plot.getDomainAxis().setLowerMargin(0.02);
plot.getDomainAxis().setUpperMargin(0.000);
domainAxis.setUpperBound(upper);
domainAxis.setLowerBound(lower);
Hi I have a timeperiod from 00:00 to 23:59 but what I try it isn't rounded and I don't see any changes..

What do you use for upper and lower values? I'm using version 1.0.13...

Best regards Peter

kasineedis
Posts: 7
Joined: Tue Mar 10, 2009 8:50 pm

Re: DateAxis tick labels

Post by kasineedis » Thu May 14, 2009 3:10 pm

Convert Time in to milliseconds by using org.jfree.date.DateUtilities.set lower and Upper margin according to your Plot Dimention .In this case 0.02 equals 2 % of axis length .You can take any date ,i took 2006,November 1st.

double lower = DateUtilities.createDate(2006, 11, 1,getHour("00:00"),getMinutes("00:00")).getTime();
double upper = DateUtilities.createDate(2006, 11, 1,getHour("23:59"),getMinutes("23:59")).getTime();
SimpleDateFormat dateFm = new SimpleDateFormat("HH:MM");
DateTickUnit dtUnit = new DateTickUnit(DateTickUnit.HOUR, 1, dateFm);
domainAxis.setTickUnit(dtUnit);
domainAxis.setAutoTickUnitSelection(true);
plot.getDomainAxis().setLowerMargin(0.02);
plot.getDomainAxis().setUpperMargin(0.000);
domainAxis.setUpperBound(upper);
domainAxis.setLowerBound(lower);



public static int getMinutes(String time) {
return Integer.parseInt(time.substring(3));
}


public static int getHour(String time) {
return Integer.parseInt(time.substring(0, 2));
}

peetzer
Posts: 11
Joined: Mon May 11, 2009 2:20 pm

Re: DateAxis tick labels

Post by peetzer » Tue May 19, 2009 7:03 am

kasineedis wrote:Convert Time in to milliseconds by using org.jfree.date.DateUtilities.set lower and Upper margin according to your Plot Dimention .In this case 0.02 equals 2 % of axis length .You can take any date ,i took 2006,November 1st.

double lower = DateUtilities.createDate(2006, 11, 1,getHour("00:00"),getMinutes("00:00")).getTime();
double upper = DateUtilities.createDate(2006, 11, 1,getHour("23:59"),getMinutes("23:59")).getTime();
SimpleDateFormat dateFm = new SimpleDateFormat("HH:MM");
DateTickUnit dtUnit = new DateTickUnit(DateTickUnit.HOUR, 1, dateFm);
domainAxis.setTickUnit(dtUnit);
domainAxis.setAutoTickUnitSelection(true);
plot.getDomainAxis().setLowerMargin(0.02);
plot.getDomainAxis().setUpperMargin(0.000);
domainAxis.setUpperBound(upper);
domainAxis.setLowerBound(lower);

public static int getMinutes(String time) {
return Integer.parseInt(time.substring(3));
}


public static int getHour(String time) {
return Integer.parseInt(time.substring(0, 2));
}
Thank you, it is more clear now.. I have set the maximum which also gave an better rounding than without. It is simular I think..

domainAxis.setMinimumDate(domainAxis.calculateLowestVisibleTickValue(new DateTickUnit (DateTickUnitType.MINUTE, interval)));
domainAxis.setMaximumDate(new Date(30000 * interval* (2880 / interval)));

At first I thought the setLowerMargin and setUpperMargin would set the space between the graph and the axis label values..

Kind regards Peter

Locked