我想知道是否可以将图表上显示的图例在x轴上垂直放置。第一次使用JFreeChart时,我不知道是否可行。


这是我的实际代码

dataset.setValue(VecDias.get(i).GetNpers(),VecDias.get(i).GetHour(),dia_semana);
JFreeChart chart = ChartFactory.createBarChart3D("Estadistica     persones/hora", "Hores","Persones",
dataset, PlotOrientation.VERTICAL, true,true, false);
chart.setBackgroundPaint(Color.white);
chart.getTitle().setPaint(Color.black);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.red);
LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
ChartPanel chartPanel = new ChartPanel(chart);
panel.add(chartPanel);

最佳答案

您可以绘制类别标签并通过JFreeChart对象更改其方向。首先从Axis获取Plot,然后更改标签方向

CategoryPlot p = chart.getCategoryPlot();
CategoryAxis axis = p.getDomainAxis();
axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);


请注意,这会更改Category标签的方向,因此您可能必须更改创建数据集对象的方式,以便正确反映类别的名称。

10-06 13:30
查看更多