2014-05-13 184 views

回答

4

您將需要使用DateFormatOverride有兩個SimpleDateFormat■一個在中間時期和另一個午夜,試試這個:

XYPlot plot = (XYPlot) chart.getPlot(); 
DateAxis axis = (DateAxis) plot.getDomainAxis(); 

axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 6, new SimpleDateFormat("HH:mm"))); 


final SimpleDateFormat hourFmt = new SimpleDateFormat("HH:mm"); 
final SimpleDateFormat datFmt = new SimpleDateFormat("d.MMM"); 

axis.setDateFormatOverride(new DateFormat(){ 

    @SuppressWarnings("deprecation") 
    @Override 
    public StringBuffer format(Date date, StringBuffer toAppendTo,FieldPosition fieldPosition) { 
     if (date.getHours() == 0) { 
      return datFmt.format(date, toAppendTo, fieldPosition); 
     } else { 
      return hourFmt.format(date, toAppendTo, fieldPosition); 
     } 
    } 

    @Override 
    public Date parse(String source, ParsePosition pos) { 
     return hourFmt.parse(source,pos); 
    } 

}); 

enter image description here

+0

謝謝。這是exatly所需要的! – nagesh