I'm able to generate the bar chart using bar jfreechart library.Coming to bar chart customization unable to reduce the bars (narrow bars instead of normal bars)width like below pic.
I am looking output like first graph but I'm getting output like second graph.
I tried chart generation with jfreechart factory.And some cutomization to bars like font and colors changing and adding own legend to the chart.But bars widths related code is not working.
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());
any suggestions that could be more helpful to my report generation.