JFreeChart Date axis Formatting issue

删除回忆录丶 提交于 2019-12-01 21:22:43
Paul Facklam

According to Adding date/time to JFreeChart graph:

"…you're using ChartFactory.createXYLineChart(), which creates a NumberAxis for the domain. Instead, use ChartFactory.createTimeSeriesChart(), which creates a DateAxis for the domain."—trashgod

Use

XYPlot plot = (XYPlot) chart.getPlot();
DateAxis dateAxis = new DateAxis();
dateAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy")); 
plot.setDomainAxis(dateAxis);

XYPlot.setDomainAxis accepts ValueAxis which is parent of DateAxis. So doing this will avoid the error.

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