I'm using TIBCO Jaspersoft Studio version 6.8.0 and I'm creating a barChart as a subReport of a main report. The barChart takes data from a sub dataset. The report is creating quite well so no complaints about that.
The barChart is built dinamically setting the width of the bars based on the number of the elements. But I'd like to set statically the width of the bars, ignoring how many elements there are.
So it would be a bar large 10 pixels (for example) both when there are 10 elements or 2 elements.
Here it is a picture showing the barChart with the correct bars' width (based on element number in it)
And here we have the same barChart but with less elements, so the bars' width would just resize dynamically (i want to set a static value to their width)
I followed some guide for creating and using a custom function for a barChart, but none of these seems to work (maybe I'm using a newer version and they were referring to an older version of Jasper Report)
I was using this, but I dont know if it's good and how to implement it in a report
package com.efarmgroup.sina.sios4.jasper;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.*;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.ui.TextAnchor;
import net.sf.jasperreports.engine.JRChart;
import net.sf.jasperreports.engine.JRChartCustomizer;
public class customBarWidth implements JRChartCustomizer{
@Override
public void customize(JFreeChart chart, JRChart jasperChart){
CategoryPlot categoryPlot = chart.getCategoryPlot();
BarRenderer br = (BarRenderer) categoryPlot.getRenderer();
br.setMaximumBarWidth(.10); // set maximum width to 35% of chart
}
}