4

I am trying to use PeriodAxis in a chart to graph some time series data. The first data point occurs at 2012-01-08 19:00:00 and the final data point occurs at 2012-01-09 19:00:00.

When the chart is drawn, the tick labels start at 19:29 and end at 19:29. I want them to start at 19:00 and end accordingly -- that is, I don't want the :29 minute fractions. I have tried to set the tick label increments to 1 hour increments using setStandardTickUnits(), but that didn't change anything. I can't seem to find any other methods for this class that would allow me to change the tick units.

enter image description here

Sample code:

PeriodAxis domain = new PeriodAxis(null, new Hour(19, new Day(8, SerialDate.JANUARY, 2012)),
            new Hour(19, new Day(9, SerialDate.JANUARY, 2012)));
domain.setAutoRangeTimePeriodClass(Hour.class);
PeriodAxisLabelInfo[] periodLabels = new PeriodAxisLabelInfo[2];
periodLabels[0] = new PeriodAxisLabelInfo(Hour.class, new SimpleDateFormat("HH:mm"));   
periodLabels[1] = new PeriodAxisLabelInfo(Day.class, new SimpleDateFormat("MMM dd, yyyy"));
domain.setLabelInfo(periodLabels);

domain.setLowerMargin(0);
domain.setUpperMargin(0);
TickUnits tu = new TickUnits();
tu.add(new DateTickUnit(DateTickUnit.HOUR, 1));

domain.setAutoTickUnitSelection(true);
domain.setStandardTickUnits(tu);
Tiago
  • 2,871
  • 4
  • 23
  • 39

1 Answers1

2

In your case, the chart starts at 19:00, and the tickUnit is 1 hour.

The issue here is that the PeriodAxis divides the horizontal axis in 24 periods, each period being represented by an org.jfree.data.time.Hour object. It then displays a label at the middle of the period : 19:29, 20:29...

In order to get what you want, you can either use a DateAxis instead of PeriodAxis, or use "hh:00" as a date format, which will replace the minute by 00.

obourgain
  • 8,856
  • 6
  • 42
  • 57