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