我添加了一个jar文件,在我的jasper报告中添加了一个图表定制器类。但是在编译它时会产生NoSuchMethodError。我已经在类路径中添加了足够的库,我使用的是jasperreports-6.5.1和jfreechart-1.5.0。
Jasper例外:
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
jar文件中的源代码:
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);
}
}
导入jar文件源和类路径的库:
该方法存在于jfreechart-1.5.0库
中