To keep the example as simple as possible, we refrained from
adding any style to the text in the crosstab. There is nothing
preventing us from altering the text to have different fonts,
alignments, etc. as discussed in Chapter 6.
In this example, the crosstab is defined by the <crosstab> element. The <rowGroup>
element defines a group to split the data into rows. In the example, each row will
display data for a different city. The <bucket> and <bucketExpression> elements
define what report expression to use as a group delimiter for <rowGroup> . In the
example, here, we used the city field as a delimiter, in order to split the rows by
city . The <crosstabRowHeader> element defines the expression to be used as a row
header. It contains a single sub-element, namely <cellContents> , which acts like an
inner band inside crosstab.
Notice that the variable name for the text field inside <crosstabRowHeader> is not
declared in the JRXML template. This is because the name assigned to <rowGroup>
(via its name attribute) creates an implicit variable. The <crosstabTotalRowHeader>
element defines the contents of the header cell for the entire row. It takes a single
<cellContents> element as its only sub-element.
The <columnGroup> element as well as its sub-elements (as illustrated in the
preceeding example) is analogous to the <rowGroup> element, except that it
influences columns instead of rows.
The <measure> element defines the calculation to be performed across rows and
columns; possible values for its calculation attribute include Average , Count ,
First , Highest , Lowest , Nothing , StandardDeviation , Sum , and Variance . These
values work just like the analogous values for the calculation attribute for report
variables. Refer to the Report Variables section in Chapter 6 for an explanation.
The <crosstabCell> element defines how data in non-header cells will be laid out.
This element also contains a single <cellContents> element as its only sub-element.
If we would like to format cells displaying 'totals' differently from other cells, we can
accomplish this by adding additional <crossTabCell> elements and setting their
rowTotalGroup and/or columnTotalGroup attributes to match the names defined in
<rowGroup> and <columnGroup> .
The <crosstab> element contains a number of sub-elements not shown in the
example. The following sections describe all sub-elements of <crosstab> . Most
of the elements shown in the following sections contain additional sub-elements.
Refer to the JasperReports Quick Reference Guide at http://jasperreports.
sourceforge.net/reference/index.html for more details.