无法自定义条形图条形宽度

时间:2019-07-16 04:33:33

标签: java jfreechart

我能够使用条形图jfreechart库生成条形图。自定义条形图后,无法减小条形图(如下图所示,以窄条代替正常条)的宽度。

enter image description here

我正在看像第一个图的输出,但是我正在看像第二个图的输出。

我尝试使用jfreechart factory生成图表。并且对条形进行了一些定制化处理,例如更改字体和颜色并在图表中添加了自己的图例。但是与条宽度相关的代码无法正常工作。

chart.setBorderVisible(false);
chart.getLegend().setPosition(RectangleEdge.BOTTOM);
Font font = new Font("SansSerif", Font.PLAIN, 12);
chart.getTitle().setFont(font);
CategoryPlot plot = chart.getCategoryPlot();
plot.setNoDataMessage("No data available");
plot.setBackgroundPaint(Color.white);
plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
plot.setFixedLegendItems(chartLegend);
plot.getDomainAxis().setLabelFont(font);
plot.getRangeAxis().setLabelFont(font);
plot.setOutlineVisible(false);
CategoryItemRenderer renderer = plot.getRenderer();
renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setDefaultItemLabelsVisible(false);
ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_CENTER);
renderer.setDefaultPositiveItemLabelPosition(position);
BarRenderer barRenderer = (BarRenderer) renderer;
for (int i = 0; i < plot.getDataset().getRowCount(); i++) {
    if (plot.getDataset().getRowKey(i).equals("FIRST_BAR")) {
        barRenderer.setSeriesPaint(i, Constants.COLOR_RED);
    }
    if (plot.getDataset().getRowKey(i).equals("SECOND_BAR)) {
        barRenderer.setSeriesPaint(i, Constants.COLOR_YELLOW);
    }
    if (plot.getDataset().getRowKey(i).equals("THIRD_BAR")) {
        barRenderer.setSeriesPaint(i, Constants.COLOR_BLUE);
    }
    if (plot.getDataset().getRowKey(i).equals("FOURTH_BAR")) {
        barRenderer.setSeriesPaint(i, Constants.COLOR_GREEN);
    }
}
barRenderer.setDrawBarOutline(false);
barRenderer.setBarPainter(new StandardBarPainter());

任何可能对我的报告生成有帮助的建议。

0 个答案:

没有答案