我正在使用JFreeChart使用CategoryPlot渲染LineChart。 像这样:
JFreeChart chart = ChartFactory.createLineChart("Daily Revenue",
"Days", "Revenue", dataset);
CategoryPlot plot = chart.getCategoryPlot();
因此,正如您所了解的那样,我必须在倾斜到45度的XAxis上显示23 Feb'18 11:00:00
之类的完整时间,
CategoryAxis categoryAxis = chart.getCategoryPlot().getDomainAxis();
categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
但是我想在XAxis上以两行显示文本,如下所示:
23 Feb'18
11:00:00
倾斜至45度。我曾尝试使用
CategoryAxis categoryAxis = chart.getCategoryPlot().getDomainAxis();
categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
categoryAxis.setMaximumCategoryLabelLines(5);
没有成功,那我该如何实现呢?
答案 0 :(得分:0)
经过一些自我研究,我发现在通过ChartUtilities.encodeAsPNG(chart.createBufferedImage(500, 300));
命令减小JFreeChart Image的宽度和高度值的同时,文本已自动调整为新行。
因此,在进行了更多研究之后,我得到了可以为我完成工作的命令。通过为CategoryAxis
的{{1}}创建X-Axis so getDomainAxis()
的对象
Y-Axis it is getRangeAxis()
然后我们使用CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
domainAxis.setMaximumCategoryLabelWidthRatio(0.25f);
并根据您的要求进行调整!