Java Reference
In-Depth Information
To populate the dataset parameters with the desired report expression, we need
to use the <crosstabDataset> element inside the <crosstab> . This element
must contain a single <dataset> element, which in turn contains a <datasetRun>
element. This element contains a name attribute indicating which subdataset to use
to populate the crosstab; it also contains a <datasetParameterExpression> sub-
element indicating what report element to use to populate the dataset parameter.
Subdatasets can also be used in a similar manner to create related charts in each
report record. To accomplish this, the <dataset> element must be placed inside the
appropriate dataset element for the chart ( <categoryDataset> , <pieDataset> , etc).
The following example demonstrates this feature for a bar chart. The report generated
by the JRXML template will display a bar chart illustrating the number of aircraft
registered in the states of Maryland, New York, and Virginia.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//
EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="ChartDatasetDemoReport" leftMargin="5"
rightMargin="5">
<subDataset name="Aircraft_Registrations">
<parameter name="StateParam" class="java.lang.String"/>
<queryString>
<![CDATA[select
a.city, count(*) as aircraft_count
from aircraft a
where a.state=$P{StateParam}
and a.city like 'A%'
group by city]]>
</queryString>
<field name="aircraft_count" class="java.lang.Integer"/>
<field name="city" class="java.lang.String"/>
</subDataset>
<queryString>
<![CDATA[select distinct state from aircraft where state in ('MD',
'NY', 'VA') order by state]]>
</queryString>
<field name="state" class="java.lang.String"/>
<detail>
<band height="200">
<textField>
<reportElement x="0" y="10" width="500" height="20"/>
<textFieldExpression>
 
Search WWH ::




Custom Search