2
가로 막대 차트 카테고리 라벨의 텍스트 정렬을 변경하려면 :, 어떻게 나는 다음과 같은 표현이 차트에서 일하고 있어요
을 ¿ 어떻게 분류 라벨 왼쪽해야합니까 정렬되었거나 정당화 되었습니까? 실제로 그들은 중심으로 보입니다. 그러나 그것은 내가 필요로하는 것이 아닙니다.
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);
감사 : 내가 사용
코드는 다음과 같다.
레이블 텍스트가 왼쪽으로 정렬됩니다. 올바른 것입니다. 이제는 왼쪽면 정렬을 해결해야합니다. Zebby에게 고마워요. – dovahkiin
왼쪽면 정렬은 위 코드에서 이미 사용 된 CategoryLabelPositions로 수행됩니다. – dovahkiin