Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)

JasperReports - Crosstabs Sample (version 4.0.1)


Crosstab and subdataset sample.

Download All Sample Source Files
Browse Sample Source Files on SVN


Main Features in This Sample

Crosstabs

Datasets


top

CrosstabsDocumented by


Description / Goal
How to use the built-in crosstab element to display aggregated data.

Since
1.1.0


[Under Construction]

top

DatasetsDocumented by Sanda Zaharia


Description / Goal
How to make use of subdatasets for chart elements and crosstab elements.

Since
1.1.0

Other Samples
/demo/samples/charts


Report Datasets

A dataset is an entity that intermediates data source and subreport characteristics. Datasets allow the engine to iterate through some virtual records, just as data sources do, but they also enable calculations and data grouping during this iteration using variables and groups. A dataset declaration, containing parameters, fields, variables, and groups, is similar to subreport declarations, but datasets are not related to any visual content. There are no sections or layout information at the dataset level.

The report data source, along with the parameters, fields, variables, and groups declared at the report level, represent a special dataset declaration, implicitely used in every report template, the so-called main dataset.
One can consider the main dataset responsible for iterating through the report data source records, calculating variables, filtering out records, and estimating group breaks during the report-filling process.

Subdatasets and Dataset Runs

User-defined datasets are declared as <subDataset/> elements. To completely characterize a subdataset one needs to set:
  1. Subdataset attributes:
    • name
    • scriptletClass
    • resourceBundle
    • whenResourceMissingType
  2. Subdataset elements:
    • <property/>
    • <scriptlet/>
    • <parameter/>
    • <queryString/>
    • <field/>
    • <sortField/>
    • <variable/>
    • <filterExpression/>
    • <group/>
Subdatasets are useful only in conjunction with some other complex elements, such as charts and crosstabs, that need to iterate through data not belonging to the main report data source itself, to retrieve specific data for the chart or perform data bucketing for the crosstab. Just simply declaring a dataset at the report level does not have any effect. The dataset has to be further referenced by a chart or crosstab element, in order to be used.

Anytime a dataset is referenced by another report element, a dataset run is instantiated. A dataset run supplies additional information about either the appropriate data source to be iterated, or the database connection string. It comes also with its own parameters and/or parameters map. Dataset runs are similar to subreports in the way parameters and the data source/connection are passed in:
 <element name="datasetRun">
  <annotation>
   <documentation>Subdataset instantiation information for a chart/crosstab dataset.</documentation>
  </annotation>
  <complexType>
   <sequence>
    <element ref="jr:parametersMapExpression" minOccurs="0" maxOccurs="1"/>
    <element ref="jr:datasetParameter" minOccurs="0" maxOccurs="unbounded"/>
    <choice minOccurs="0" maxOccurs="1">
     <element ref="jr:connectionExpression"/>
     <element ref="jr:dataSourceExpression"/>
    </choice>
   </sequence>
   <attribute name="subDataset" type="string" use="required">
	<annotation>
 	 <documentation>The name of the <elem>subdataset</elem> to instantiate.</documentation>
	</annotation>
   </attribute>
  </complexType>
 </element>
The subDataset attribute is mandatory and contains the name of the subdataset to be used during the chart or crosstab filling process. If no dataset run is specified for a chart or crosstab, the main dataset of the report is used by default.



© 2001-2010 Jaspersoft Corporation www.jaspersoft.com