I have a graph with two bars on each category value. How can we remove sapce beween bar on a category value. Space between bar of of with different category value should not be removed.
Asked
Active
Viewed 1,451 times
2 Answers
3
I worked on this case using java customizer as follow:
public class BarChartCustomizerExIm implements JRChartCustomizer{
@Override
public void customize(JFreeChart chart, JRChart jasperChart) {
BarRenderer barRenderer = (BarRenderer)plot.getRenderer();
barRenderer.setItemMargin(0);
}
}
Put jar for this class in your class path and in customizer field in your ireport specify the classname.

Madhusudan
- 4,637
- 12
- 55
- 86
2
Write your own ChartCustomizer as follow:
public class CustomizeBarChart extends JRAbstractChartCustomizer {
/**
* Customizer for BarChart.
*
* @param chart the chart
* @param jasperChart the jasperChart
*
* @see net.sf.jasperreports.engine.JRChartCustomizer#customize(org.jfree.chart.JFreeChart, net.sf.jasperreports.engine.JRChart)
*/
public void customize(JFreeChart chart, JRChart jasperChart) {
CategoryPlot categoryPlot = chart.getCategoryPlot();
BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();
//Spaces between bars
renderer.setItemMargin(0.01);
}
}
And add it as Customizer class in your chart preferences.

Vlad
- 350
- 3
- 13
-
This will set sapce between all bars. But I want to remove space between bar on a category value. I have two bars for one category value. – वरुण May 13 '15 at 09:31
-
3it reduce spaces between bars, try to set 0.00 instead of 0.01 – Vlad May 13 '15 at 09:33
-
When I use this code `renderer.setMaximumBarWidth(0.03);` also in the class It again starts showing space between bars. – वरुण May 13 '15 at 09:38
-
Do you have any solution for this? – वरुण May 14 '15 at 05:22
-
I have no idea. Also look at this answer:http://stackoverflow.com/a/16738907/4580058 – Vlad May 14 '15 at 06:58
-
It did not work with 4 bars in graph. It works if there are more bars in graph. – वरुण May 20 '15 at 12:14
-
It sounds strange, but try to set renderer.setItemMargin(-0.0); with minus before. If you use renderer.setMaximumBarWidth(0.03), then set -0.4 – Vlad May 20 '15 at 13:16
-
This also did not work. Negative sign reverses position of columns. – वरुण May 21 '15 at 06:56