1

I have added a jar file to add a chart customizer class in my jasper report. But when compiling it gives the NoSuchMethodError. I have added enough libraries to the classpath and I am using jasperreports-6.5.1 and jfreechart-1.5.0.

Jasper exception:

java.lang.NoSuchMethodError: org.jfree.chart.title.LegendTitle.setItemLabelPadding(Lorg/jfree/chart/ui/RectangleInsets;)V null 
java.lang.NoSuchMethodError: org.jfree.chart.title.LegendTitle.setItemLabelPadding(Lorg/jfree/chart/ui/RectangleInsets;)V

Source code in the jar file:

public class ChartCustomizer extends JRAbstractChartCustomizer {
DecimalFormat twoPlaces = new DecimalFormat("0.00");

@Override
public void customize(JFreeChart jFreeChart, JRChart jrChart) {
    if (jFreeChart.getPlot().getClass().equals(PiePlot3D.class)) {
        formatPiePlot3D((PiePlot3D) jFreeChart.getPlot());            
    } else if (jFreeChart.getPlot().getClass().equals(PiePlot.class)) {
        formatPiePlot((PiePlot) jFreeChart.getPlot());
    }
    LegendTitle legend = jFreeChart.getLegend();
    legend.setItemLabelPadding(new RectangleInsets(2, 2, 2, 999999999));
}

private void formatPiePlot3D(PiePlot3D plot) {
    PieSectionLabelGenerator labelGenerator = new StandardPieSectionLabelGenerator("{2}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    PieSectionLabelGenerator legendGenerator = new StandardPieSectionLabelGenerator("{0} - {1}", new DecimalFormat("#,##0.00", new DecimalFormatSymbols(new Locale("en_US"))), new DecimalFormat("0%"));
    plot.setLegendLabelGenerator(legendGenerator);
    plot.setLabelGenerator(labelGenerator);
}

private void formatPiePlot(PiePlot plot) {
    PieSectionLabelGenerator labelGenerator = new StandardPieSectionLabelGenerator("{2}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    PieSectionLabelGenerator legendGenerator = new StandardPieSectionLabelGenerator("{0} - {1}", new DecimalFormat("#,##0.00", new DecimalFormatSymbols(new Locale("en_US"))), new DecimalFormat("0%"));
    plot.setLegendLabelGenerator(legendGenerator);
    plot.setLabelGenerator(labelGenerator);
} 

}

Libraries imported to the jar file source and classpath:

  • jcommon-1.0.24
  • jfreechart-1.5.0
  • jasperreports-6.5.1
  • jfreesvg-3.3

The method exists in jfreechart-1.5.0 library

The method is exists in jfreechart-1.5.0 library

  • 1
    JR 6.5.1 is using org.jfree:jfreechart:1.0.19. You should check pom.xml – Alex K Jun 12 '18 at 11:08
  • You should also check the dependencies tree for several versions of the same library – Alex K Jun 12 '18 at 11:30
  • 1
    @Alex K This is not a maven project so I cannot check the pom.xml. With jfreechart:1.0.19 it's working fine. Is it impossible to use jfreechart-1.5.0 with jasperreports-6.5.1? – Ishani Samaraweera Jun 12 '18 at 11:48
  • `Is it impossible to use jfreechart-1.5.0 with jasperreports-6.5.1?` - It is hard to say. Vendor is using `org.jfree:jfreechart:1.0.19` at 6.5.1 verson. The library was tested with this version of *jfreechart*. If the only one version of *jfreechart* at your classpath, looks like you answered at your question by yourself :) – Alex K Jun 12 '18 at 12:47

0 Answers0