Reputation: 65
I have Created one Barchart in ireport 3.0, the problem is that the bars are very thin. When i tried to increase bar width through customize r class it doesn't reflect any changes in size of bar i.e. width is same as it was. So how to increase width of bars of bar chart? I am attaching an image copy for your understanding purpose.
Bar width is shown in figure.
Upvotes: 1
Views: 2476
Reputation: 159
I have faced same issue as well. After a long search i found some solutions which fixed my issue. jasper report bar chart's bar width depends on chart's height and width. as jasper use JFreechart in backend so many modifications possible by a customize class. For increasing bar's width you need a customization class and then add it to your barchart jrxml like bellow
public class JasperBarChartCustomization implements JRChartCustomizer {
@Override
public void customize(JFreeChart chart, JRChart jasperChart) {
CategoryPlot catPlot = (CategoryPlot) chart.getPlot();
BarRenderer renderer = (BarRenderer) catPlot.getRenderer();
renderer.setMaximumBarWidth(.08);//for max width//
renderer.setItemMargin(-2);//as much margin decrease that much bar width increase//
//for adding value ob bar//
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
renderer.setBaseItemLabelPaint(Color.WHITE);
renderer.setBaseItemLabelFont(new Font("fontname", Font.PLAIN, 6));
//for remove legend background color and box border//
if (chart.getLegend() != null) {
chart.getLegend().setBorder(0.0, 0.0, 0.0, 0.0);
LegendTitle legend = chart.getLegend();
legend.setBorder(0, 0, 0, 0);
legend.setFrame(BlockBorder.NONE);
}
}
}
Now create a jar from above class and use that jar in ur jasper project's classpath
If your jasper run inside java application then u can use the class directly without making jar. create customize class in you code base
Upvotes: 0