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.