我想为x轴设置不同的刻度标签格式
.
11月1日然后时间格式应该是小时..
是否可以使用jFreeChart TimePeriodValues和TimePeriodValuesCollection数据集.
你需要在中间阶段DateFormatOverride使用两个SimpleDateFormats,在午夜使用另一个,试试这个:
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);
}
});
Run Code Online (Sandbox Code Playgroud)
