How to remove space betwwen bars on a category in

2019-06-09 21:15发布

问题:

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.

回答1:

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.



回答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.