我正在使用具有以下演示文稿的图表:
¿ 如何使类别标签左对齐或对齐?实际上它们看起来居中,但这不是我所需要的。
我正在使用的代码如下:
JFreeChart chart = getChart();
CategoryPlot plot = (CategoryPlot) chart.getPlot();
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(true);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setMaximumCategoryLabelLines(5);
CategoryLabelPositions p = domainAxis.getCategoryLabelPositions();
CategoryLabelPosition left = new CategoryLabelPosition(
RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
TextAnchor.CENTER_LEFT, 0.0,
CategoryLabelWidthType.RANGE, 0.70f //Assign 70% of space for category labels
);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions
.replaceLeftPosition(p, left));
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BasicStroke stroke = new BasicStroke(1);
plot.setDomainGridlinePaint(Color.black);
plot.setDomainGridlineStroke(stroke);
plot.setRangeGridlinePaint(Color.black);
plot.setRangeGridlineStroke(stroke);
CategoryDataset cd = plot.getDataset();
setBarColors(renderer, plot, cd);
谢谢。