jFreeChart: DateAxis to behave like a CategoryAxis. Only discrete datevalues to be printed

我的未来我决定 提交于 2019-12-01 09:53:59

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/3416042/jfreechart-dateaxis-to-behave-like-a-categoryaxis-only-discrete-datevalues-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!