DateAxis tick labels
DateAxis tick labels
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?
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?
Re: DateAxis tick labels
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.
- 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.
Re: DateAxis tick labels
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.
I have added 1ms to setUpperBound and setLowerBound, and now tick labels are as I wanted.
-
- Posts: 7
- Joined: Tue Mar 10, 2009 8:50 pm
DateAxis tick labels
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?
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?
Re: DateAxis tick labels
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.
To be clear, you can set one or the other, but not both, or you can override the method I mentioned.
-
- Posts: 7
- Joined: Tue Mar 10, 2009 8:50 pm
Re: DateAxis tick labels
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);
domainAxis.setAutoTickUnitSelection(true);
plot.getDomainAxis().setLowerMargin(0.02);
plot.getDomainAxis().setUpperMargin(0.000);
domainAxis.setUpperBound(upper);
domainAxis.setLowerBound(lower);
Re: DateAxis tick labels
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..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);
What do you use for upper and lower values? I'm using version 1.0.13...
Best regards Peter
-
- Posts: 7
- Joined: Tue Mar 10, 2009 8:50 pm
Re: DateAxis tick labels
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));
}
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));
}
Re: DateAxis tick labels
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..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));
}
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