JFreeChart PeriodAxis: 29 minutes of fractions

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

When the chart is drawn, cue marks begin at 19:29 and end at 19:29. I want them to start at 19:00 and end accordingly - that is, I do not want: 29-minute fractions. I tried to set tag label increments in 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

Code example:

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); 
+4
source share
1 answer

In your case, the schedule starts at 19:00, and tickUnit - 1 hour.

The problem here is that PeriodAxis divides the horizontal axis into 24 periods, each period is represented by the org.jfree.data.time.Hour object. Then it displays a label in the middle of the period: 19:29, 20:29 ...

To get what you want, you can use DateAxis instead of PeriodAxis or use "hh:00" as the date format, which will replace the minute with 00.

+2
source

All Articles