How to remove space betwwen bars on a category in

2019-06-09 21:17发布

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.

2条回答
Melony?
2楼-- · 2019-06-09 21:26

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.

查看更多
Rolldiameter
3楼-- · 2019-06-09 21:42

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.

查看更多
登录 后发表回答