I have a project using DynamicJasper to create reports. While this works, but when I wanted to add a chart to a previously functional report, I ran into problems.
I keep getting the following:
net.sf.jasperreports.engine.design.JRValidationException: report design is invalid: 1. Field not found: customExpression_for_Ganancia at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign (JRAbstractCompiler.java:258) at net.sf.jasper .engine.design.JRAbstractCompiler.compileReport (JRAbstractCompiler.java:140) at net.sf.jasperreports.engine.JasperCompileManager.compileReport (JasperCompileManager.java:215) on ar.com.fdvs .dj.core.DynamicJperHperperperJperHperper .java: 519) on ar.com.fdvs .dj.core.DynamicJasperHelper.generateJasperPrint (DynamicJasperHelper.java:279) on ar.com.fdvs .dj.core.DynamicJasperHelper.generateJasperPrint (DynamicJasperHelper.java:232)
Ganancia is the only column in the chart that is CustomExpression. If I do not add this column to the series in the chart, the chart will display correctly. It seems that the diagram does not work very well with expressions ...
Excerpt from my code:
private DynamicReport buildSalesReport() throws ColumnBuilderException, ClassNotFoundException, ChartBuilderException { DynamicReportBuilder drb = new DynamicReportBuilder(); drb.setReportName("Reporte de Ventas") .setTitle("Reporte de ventas") .setSubtitle("Este reporte fue generado el " + new Date()) .setPrintColumnNames(false) .setIgnorePagination(true) .setMargins(10, 10, 10, 10) .setUseFullPageWidth(true); Style groupOneStyle = new Style(); groupOneStyle.setFont(Font.ARIAL_BIG); groupOneStyle.setHorizontalAlign(HorizontalAlign.LEFT); groupOneStyle.setVerticalAlign(VerticalAlign.MIDDLE); AbstractColumn columnDisplayName = ColumnBuilder.getNew() .setColumnProperty("bookingType.displayName", String.class.getName()) .setTitle("Tipo").setWidth(new Integer(40)) .setStyle(groupOneStyle) .build(); AbstractColumn columnDestiny = ColumnBuilder.getNew() .setColumnProperty("bookedObject.destiny", String.class.getName()) .setTitle("Destino").setWidth(new Integer(40)) .build(); Style priceStyle = new Style(); priceStyle.setHorizontalAlign(HorizontalAlign.RIGHT); AbstractColumn columnCurrency = ColumnBuilder.getNew() .setColumnProperty("bookedObject.currency.displayName", String.class.getName()) .setTitle("Cotizacion").setWidth(new Integer(5)) .setShowText(false) .build(); Style footerStyle = new Style(); footerStyle.setFont(Font.ARIAL_MEDIUM); footerStyle.setBorderTop(Border.THIN); footerStyle.setHorizontalAlign(HorizontalAlign.RIGHT); footerStyle.setVerticalAlign(VerticalAlign.MIDDLE); AbstractColumn columnPrice = ColumnBuilder.getNew() .setColumnProperty("bookedObject.price", Double.class.getName()) .setStyle(priceStyle) .setPattern("$ 0.00") .setTitle("Precio").setWidth(new Integer(25)) .build(); AbstractColumn columnCount = ColumnBuilder.getNew() .setColumnProperty("count", Integer.class.getName()) .setStyle(priceStyle) .setTitle("Cantidad").setWidth(new Integer(25)) .build(); columnCount.setName("Cantidad"); AbstractColumn columnProfit = ColumnBuilder.getNew() .setCustomExpression(this.getProfitExpression()) .setStyle(priceStyle) .setTitle("Ganancia").setWidth(new Integer(20)) .setPattern("$ 0.00") .build(); columnProfit.setName("Ganancia"); GroupBuilder groupBookingTypeBuilder = new GroupBuilder(); DJGroup groupBookingType = groupBookingTypeBuilder.setCriteriaColumn((PropertyColumn) columnDisplayName) .setGroupLayout(GroupLayout.VALUE_IN_HEADER_WITH_HEADERS_AND_COLUMN_NAME) .build(); GroupBuilder groupCurrencyBuilder = new GroupBuilder(); DJGroup groupCurrency = groupCurrencyBuilder.setCriteriaColumn((PropertyColumn) columnCurrency) .addFooterVariable(columnCount,DJCalculation.SUM,footerStyle) .addFooterVariable(columnProfit,DJCalculation.SUM,footerStyle) .setGroupLayout(GroupLayout.VALUE_IN_HEADER) .build(); drb.addColumn(columnDisplayName) .addColumn(columnCurrency) .addColumn(columnDestiny) .addColumn(columnCount) .addColumn(columnPrice) .addColumn(columnProfit) .addGroup(groupBookingType) .addGroup(groupCurrency) .setPrintBackgroundOnOddRows(true); DJAxisFormat categoryAxisFormat = new DJAxisFormat("Destino"); categoryAxisFormat.setLabelFont(Font.ARIAL_SMALL); categoryAxisFormat.setLabelColor(Color.DARK_GRAY); categoryAxisFormat.setTickLabelFont(Font.ARIAL_SMALL); categoryAxisFormat.setTickLabelColor(Color.DARK_GRAY); categoryAxisFormat.setTickLabelMask(""); categoryAxisFormat.setLineColor(Color.DARK_GRAY); DJAxisFormat valueAxisFormat = new DJAxisFormat("Ventas / Ingresos"); valueAxisFormat.setLabelFont(Font.ARIAL_SMALL); valueAxisFormat.setLabelColor(Color.DARK_GRAY); valueAxisFormat.setTickLabelFont(Font.ARIAL_SMALL); valueAxisFormat.setTickLabelColor(Color.DARK_GRAY); valueAxisFormat.setTickLabelMask("#,##0"); valueAxisFormat.setLineColor(Color.DARK_GRAY); DJChart djChart = new DJBarChartBuilder()
As I said, the report is displayed correctly without a chart; with a chart, it fails only if the expression column is included as a series.
Any ideas are welcome!
source share