I have a JFreeChart standard TimelineGraph. There is an Y Axis with numbers from 0 to 600, and a X Axis to show the period of time you wish to see.
I have implemented the following code:
protected void setupDomainAxis() {
final long periodMillis = to.toDate().getTime() - from.toDate().getTime();
if (periodMillis <= DAY_IN_MILLIS) {
DateAxis domainAxis = new DateAxis();
domainAxis.setDateFormatOverride(new SimpleDateFormat(UserContext.getCurrentUser().getTimeFormat().getPattern()));
domainAxis.setRange(new DateRange(from.toDate(), to.toDate()), true, true);
domainAxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
domainAxis.setMinorTickMarksVisible(true);
domainAxis.setMinorTickCount(2);
getPlot().setDomainAxis(domainAxis);
}
else if (periodMillis == 172799999) {
PeriodAxis domainAxis = new PeriodAxis(null);
PeriodAxisLabelInfo[] info = new PeriodAxisLabelInfo[1];
info[0] = new PeriodAxisLabelInfo(Day.class,
new SimpleDateFormat(UserContext.getCurrentUser().getDateFormat().getWeekdayPattern(), LocaleContextHolder.getLocale()));
domainAxis.setLabelInfo(info);
domainAxis.setMinorTickMarksVisible(true);
domainAxis.setMinorTickMarkOutsideLength(1);
domainAxis.setMinorTickCount(3);
domainAxis.setRange(new DateRange(from.toDate(), to.toDate()), true, true);
getPlot().setDomainAxis(domainAxis);
}
}
The first part of the method works great. The difference between the first part and the second part is the type of the domainAxis
.
As a DateAxis
I can set the setMinorTickCount(2);
method, but as a PeriodAxis
I can set the visibility, the marklength, but not the number of ticks.
Anybody an idea? I don´t understand why, because both kinds of Axis inherit from org.jfree.chart.axis.ValueAxis
and have the setMinorTickCount(int count)
method.