Jump to content
Changes to the Jaspersoft community edition download ×
  • Bar Chart: how to display labels of the bars


    stasp

    Issue Description:

    On the bars of the bar chart, sometimes not all values ​​of the bar labels are displayed. This will depend on the displayed data (size of the particular bars)


    Resolution:

    This is a known limitation. When bars on charts reach the outer edges of the chart, some of labels get cut off. 

    A possible workaround to avoid labels truncation is to write a chart customizer implementing the JRChartCustomizer interface, similar to the following:

    import net.sf.jasperreports.engine.JRChart;
    import net.sf.jasperreports.engine.JRChartCustomizer;
    import org.jfree.chart.plot.*;
    import org.jfree.ui.*;
    public class PlotInsetCustomizer implements JRChartCustomizer{
        public PlotInsetCustomizer() {}
        public void customize(JFreeChart jfc, JRChart chart){
            double top = 15.0;    // this is the inset you need to adjust to make sure
                                  // that there is enough space to display the truncated label
            double bottom = 5.0;
            double left = 5.0;
            double right = 5.0;
            XYPlot plot = (XYPlot)jfc.getPlot();
            plot.setInsets(new RectangleInsets(top, bottom, left, right));
            //adjust the "top" value to make sure it is big enough to accommodate the missing label
        }
    }
    

    There is some information about implementing chart customizers in section 12.4 Properties of Charts if the iReport Ultimate Guide, and also in JasperReports Ultimate guide.


    References:


    Ref. Case #00028310


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...