Simple example doesn't work correctly

0

I've created a simple JasperReport example:

StackOverflowExample.jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="StackOverflowExample" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <queryString>
        <![CDATA[SELECT DISTINCT "ORDERS"."SHIPCOUNTRY"
FROM "ORDERS"]]>
    </queryString>
    <field name="SHIPCOUNTRY" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="SHIPCOUNTRY"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="183">
            <subreport>
                <reportElement x="0" y="0" width="556" height="170" isRemoveLineWhenBlank="true" uuid="4b89b974-f838-4bb7-85b6-1b0f1079c1e6"/>
                <subreportParameter name="country">
                    <subreportParameterExpression><![CDATA[$F{SHIPCOUNTRY}]]></subreportParameterExpression>
                </subreportParameter>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA["StackOverflowExampleSubReport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>
 

And the subreport, StackOverflowExampleSubReport.jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="StackOverflowExample" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <parameter name="country" class="java.lang.String">
        <defaultValueExpression><![CDATA["France"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT "ORDERS"."ORDERDATE",
    "ORDERS"."FREIGHT"
FROM "ORDERS"
WHERE  "ORDERS"."SHIPCOUNTRY" = $P{country}]]>
    </queryString>
    <field name="ORDERDATE" class="java.sql.Timestamp">
        <property name="com.jaspersoft.studio.field.label" value="ORDERDATE"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
    </field>
    <field name="FREIGHT" class="java.math.BigDecimal">
        <property name="com.jaspersoft.studio.field.label" value="FREIGHT"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="160">
            <lineChart>
                <chart evaluationTime="Report">
                    <reportElement x="15" y="5" width="255" height="155" isRemoveLineWhenBlank="true" uuid="3b5f7d89-490b-468f-9112-f606f4eda437">
                        <printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
                    </reportElement>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <categoryDataset>
                    <categorySeries>
                        <seriesExpression><![CDATA[$P{country}]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{ORDERDATE}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{FREIGHT}]]></valueExpression>
                    </categorySeries>
                </categoryDataset>
                <linePlot>
                    <plot/>
                    <categoryAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                    </categoryAxisFormat>
                    <valueAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                    </valueAxisFormat>
                </linePlot>
            </lineChart>
        </band>
    </detail>
</jasperReport>
 

The report use the sample DB, and here are the screen shoot:

  • SubReport, with the parameter country set to "France", it contain the first page as below and 7 other empty pages.

  • MainReport, The first two page as below, a total of 93 pages, most of them which are empty

 

ho.hince's picture
Joined: Jun 25 2019 - 12:48am
Last seen: 1 month 6 days ago

2 Answers:

1

Here we go, much better I believe. 
StackOverflowExample.jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="StackOverflowExample" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <queryString>
        <![CDATA[SELECT DISTINCT "ORDERS"."SHIPCOUNTRY"
FROM "ORDERS"]]>
    </queryString>
    <field name="SHIPCOUNTRY" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="SHIPCOUNTRY"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="40">
            <subreport>
                <reportElement x="0" y="0" width="556" height="40" isRemoveLineWhenBlank="true" uuid="4b89b974-f838-4bb7-85b6-1b0f1079c1e6"/>
                <subreportParameter name="country">
                    <subreportParameterExpression><![CDATA[$F{SHIPCOUNTRY}]]></subreportParameterExpression>
                </subreportParameter>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA["StackOverflowExampleSubReport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>

StackOverflowExampleSubReport.jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="StackOverflowExample" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <parameter name="country" class="java.lang.String">
        <defaultValueExpression><![CDATA["France"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT "ORDERS"."ORDERDATE",
    "ORDERS"."FREIGHT"
FROM "ORDERS"
WHERE  "ORDERS"."SHIPCOUNTRY" = $P{country}]]>
    </queryString>
    <field name="ORDERDATE" class="java.sql.Timestamp">
        <property name="com.jaspersoft.studio.field.label" value="ORDERDATE"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
    </field>
    <field name="FREIGHT" class="java.math.BigDecimal">
        <property name="com.jaspersoft.studio.field.label" value="FREIGHT"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="155">
            <lineChart>
                <chart evaluationTime="Report">
                    <reportElement x="0" y="0" width="255" height="155" isRemoveLineWhenBlank="true" uuid="3b5f7d89-490b-468f-9112-f606f4eda437"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <categoryDataset>
                    <categorySeries>
                        <seriesExpression><![CDATA[$P{country}]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{ORDERDATE}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{FREIGHT}]]></valueExpression>
                    </categorySeries>
                </categoryDataset>
                <linePlot>
                    <plot/>
                    <categoryAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                    </categoryAxisFormat>
                    <valueAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                    </valueAxisFormat>
                </linePlot>
            </lineChart>
        </band>
    </summary>
</jasperReport>

This will produce 6 pages, 4 charts on each page execpt one on the last page. 
 

joseng62's picture
620
Joined: Dec 5 2014 - 2:43am
Last seen: 1 month 1 week ago
0
ho.hince's picture
Joined: Jun 25 2019 - 12:48am
Last seen: 1 month 6 days ago
Feedback
randomness