2013-01-09 47 views
4

我想在圖表中使用PeriodAxis來繪製一些時間序列數據。第一個數據點發生在2012-01-08 19:00:00,最終數據點發生在2012-01-09 19:00:00。JFreeChart PeriodAxis:29分鐘分數

繪製圖表時,刻度標籤從19:29開始到19:29結束。我希望他們在19:00開始並相應地結束 - 也就是說,我不想要:29分鐘的分數。我試圖使用setStandardTickUnits()將刻度標籤增量設置爲1小時增量,但這並沒有改變任何東西。我似乎無法找到任何其他方法,這將允許我更改刻度單位。

enter image description here

示例代碼:

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); 

回答

2

在你的情況,圖表開始於19:00,而tickUnit爲1小時。

這裏的問題是PeriodAxis將水平軸分爲24個週期,每個週期由一個org.jfree.data.time.Hour對象表示。然後,它在週期的中間顯示的標籤:19:29,20:29 ...

爲了得到你想要的東西,你可以使用的DateAxis代替PeriodAxis,或使用"hh:00"爲日期格式,這將取代00分鐘。

+1

我需要使用PeriodAxis,所以我會將我的日期格式設置爲「hh:00」。謝謝。 – Tiago