jFreeChart: DateAxis to behave like a CategoryAxis. Only discrete datevalues to be printed
I have a TimeSeries Chart with a XYdataset which has the milliseconds of each dates. Now I want to have a chart that only displays each date one time on the axis, no matter what the range of dates is. I already got it so far, that only the date is printed, not the time (via setNumberFormatOverride() method). What I have now, is this: alt text http://dl.getdropbox.com/u/1144075/Bildschirmfoto%202010-08-05%20um%2016.51.39.JPG
What I want, is this: alt text http://dl.getdropbox.com/u/1144075/Bildschirmfoto%202010-08-05%20um%2016.54.54.JPG
This is a snippet of my code. also, the setLabelAngle() method don't work?!
JFreeChart chart = ChartFactory.createTimeSeriesChart(...);
XYPlot xyplot = (XYPlot)chart.getPlot();
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setLabelAngle(Math.PI / 6.0);`
numberaxis.setNumberFormatOverride((DecimalFormat)DecimalFormat.getInstance(Locale.GER开发者_C百科MAN));
You can set the TickUnit
to any convenient DateTickUnitType
. I use DAY
in this example and MMM
to verify the Locale
:
axis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1,
new SimpleDateFormat("dd.MMM.yy", Locale.GERMAN)));
As you are a returning customer, I'll address the second question, too: setLabelAngle()
works perfectly well, but it changes the axis label in the chart legend. Using setVerticalTickLabels()
is an alternative for the tick labels themselves:
axis.setVerticalTickLabels(true);
精彩评论