Crosstabs are a great feature introduced by JasperReports, now it is possible to create crosstabs through DynamicJasper.

The above crosstab was generated with a fragment like this:
FastReportBuilder drb = new FastReportBuilder();
drb
.setTitle("November 2006 sales report")
.setSubtitle("This report was generated at " + new Date())
.setPageSizeAndOrientation(Page.Page_A4_Landscape())
.setPrintColumnNames(false)
.setUseFullPageWidth(true)
.setDefaultStyles(titleStyle, null, null, null);
DJCrosstab djcross = new CrosstabBuilder()
.setHeight(200)
.setWidth(500)
.setHeaderStyle(mainHeaderStyle)
.setDatasource("sr",DJConstants.DATA_SOURCE_ORIGIN_PARAMETER, DJConstants.DATA_SOURCE_TYPE_COLLECTION)
.setUseFullWidth(true)
.setColorScheme(DJConstants.COLOR_SCHEMA_LIGHT_GREEN)
.setAutomaticTitle(true)
.setCellBorder(Border.THIN)
.addColumn("State","state",String.class.getName(),false)
.addColumn("Branch","branch",String.class.getName(),false)
.addRow("Product Line", "productLine", String.class.getName(),false)
.addRow("Item", "item", String.class.getName(),true)
.addMeasure("amount",Float.class.getName(), ColumnsGroupVariableOperation.SUM , "Amount",measureStyle)
.setRowStyles(colAndRowHeaderStyle, totalStyle, totalHeaderStyle)
.setColumnStyles(colAndRowHeaderStyle, totalStyle, totalHeaderStyle)
.setCellDimension(17, 60)
.setColumnHeaderHeight(30)
.setRowHeaderWidth(80)
.build();
drb.addHeaderCrosstab(djcross); //add the crosstab in the header band of the report
DynamicReport dr = drb.build();
//put a collection in the parameters map to be used by the crosstab
params.put("sr", SortUtils.sortCollection(TestRepositoryProducts.getDummyCollection(),djcross));
There is no limit about how many columns or rows the crosstab contains.
The data must be sorted with the following criteria: row(1), ..., row(n), column(1), ..., column(m)
row(1) will be the outer-most row, row(n) will be the inner-most row
column(1) will be the outer-most column, column(m) will be the inner-most column
Where:
For example, if path to the data source is "subreportDatasource" and origin of the data source is SUBREPORT_DATA_SOURCE_ORIGIN_PARAMETER, then it will look in the parameters map for an object under the key of "subreportDatasource", on the other hand if we pass SUBREPORT_DATA_SOURCE_ORIGIN_FIELD, in the current row, there must be a property with the name "subreportDatasource" that returns an object of the type DATA_SOURCE_TYPE_<XXX>
Where:
Where:
Where:
Defines the dimension of the inner-most cell
See also Multiple measure Crosstabs
Refer to CrosstabReportTest4.html for a working example.
Also, these other examples show other ways to create crosstabs and add them to group headers and footers
One column, one row

2 columns, 1 row

1 column, 2 rows

2 columns, 2 rows

3 columns, 2 rows
