I've created a simple JasperReport example, using the sample DB:
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>
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 problem is that I have a lot of empty useless space
Subreport
An image of the subreport, with the parameter country set to "France", it contains the first page as below and 7 other empty pages
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture.png
MainReport
For the main report, the first two page as below, there is a total of 93 pages, most of them which are empty:
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture_0.png
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture_1.png
The reason for the white space is that I print the chart in the subreport report once. I do it with the property printWhen.
printWhen => new Boolean($V{REPORT_COUNT}.intValue()==1)
I can't move the chart out of the Detail band, because I've set the subreport properties with Column Count = 2 and Print Order = Horizontal. I did that, cause I wish to have the charts in two column just like that:
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture_2.png
(The problem here is that the chart are duplicated)
I found the solution, I was printing the chart only once, but I was printing the Detail band each time, so I had to move the print when expression to the Detail band.
<band height="160">
<printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
The main chart must have two column in vertical order, and the subreport 2 column in horizontal order.
EDIT
You can also change the main report properties :Print Order ==> vertical and Column Count ==> 2
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" columnCount="2" 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=""/>
<queryString>
<![CDATA[SELECT "ORDERS"."SHIPCOUNTRY",
Max("ORDERS"."SHIPCOUNTRY")
FROM "ORDERS"
GROUP BY "ORDERS"."SHIPCOUNTRY"
ORDER BY "ORDERS"."SHIPCOUNTRY" ASC]]>
</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>
<field name="C2" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="C2"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="170">
<subreport>
<reportElement x="-20" y="50" width="297" height="120" isRemoveLineWhenBlank="true" uuid="4b89b974-f838-4bb7-85b6-1b0f1079c1e6">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<subreportParameter name="country">
<subreportParameterExpression><![CDATA[$F{SHIPCOUNTRY}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["StackOverflowExampleSubReport.jasper"]]></subreportExpression>
</subreport>
<textField>
<reportElement x="43" y="0" width="185" height="50" uuid="0c170024-70ea-492f-95fe-99ff3a27cb6d"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="19"/>
</textElement>
<textFieldExpression><![CDATA[$F{SHIPCOUNTRY}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
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="130">
<printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
<lineChart>
<chart evaluationTime="Report">
<reportElement isPrintRepeatedValues="false" x="0" y="3" width="235" height="125" 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>
</detail>
</jasperReport>
Related
I'm looking for any suggestions on how to print a new/different page for different organization IDs. I created a jaspersoft grouping and was thinking of adding a print when expression to the organization ID group header. Would that be the way to go? Can anyone help me with the expression that I would need for that?
"Start New Page" (isStartNewPage="true") in the Appearance tab of the Properties for the Group Header is all that is necessary to start on a new page for every new group. Group Expression for your situation would simply be something like $F{organizationID}.
Here's an example that groups on $F{city}, lists $F{CustomerID} and starts a new page for every new $F{city}:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.1.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="Blank_A4_" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="62ac07f5-f11e-4179-aedb-a42e850c1ea8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="northwind"/>
<queryString language="jsonql">
<![CDATA[Northwind.Customers]]>
</queryString>
<field name="City" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="City"/>
<fieldDescription><![CDATA[City]]></fieldDescription>
</field>
<field name="CustomerID" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="CustomerID"/>
<fieldDescription><![CDATA[CustomerID]]></fieldDescription>
</field>
<group name="City" isStartNewPage="true">
<groupExpression><![CDATA[$F{City}]]></groupExpression>
</group>
<columnHeader>
<band height="12" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="12" uuid="bdf3f7ab-bf1d-451e-a2ad-831a551ce388"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Company Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="12" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="12" uuid="c7bcc5aa-8051-48ad-a0d6-fe27c68da204"/>
<textFieldExpression><![CDATA[$F{CustomerID}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I've created a report, that you can find here:
Jasper, 'print when' create white space,
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" columnCount="2" 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=""/>
<queryString>
<![CDATA[SELECT "ORDERS"."SHIPCOUNTRY",
Max("ORDERS"."SHIPCOUNTRY")
FROM "ORDERS"
GROUP BY "ORDERS"."SHIPCOUNTRY"
ORDER BY "ORDERS"."SHIPCOUNTRY" ASC]]>
</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>
<field name="C2" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="C2"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="170">
<subreport>
<reportElement x="-20" y="50" width="297" height="120" isRemoveLineWhenBlank="true" uuid="4b89b974-f838-4bb7-85b6-1b0f1079c1e6">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<subreportParameter name="country">
<subreportParameterExpression><![CDATA[$F{SHIPCOUNTRY}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["StackOverflowExampleSubReport.jasper"]]></subreportExpression>
</subreport>
<textField>
<reportElement x="43" y="0" width="185" height="50" uuid="0c170024-70ea-492f-95fe-99ff3a27cb6d"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="19"/>
</textElement>
<textFieldExpression><![CDATA[$F{SHIPCOUNTRY}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
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="130">
<printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
<lineChart>
<chart evaluationTime="Report">
<reportElement isPrintRepeatedValues="false" x="0" y="3" width="235" height="125" 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>
</detail>
</jasperReport>
This report works, what I have is this
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture_report_test.png
The problem :
The order is vertical. What we can see is Argentina, Brazil, Austria, Canada, etc.. But I want to have Argentina, Austria, Belgium, Brazil, etc..
If I change the print order to horizontal, I get the error :
Subreport overflowed on a band that does not support overflow.
The answer Subreport overflowed on a band that does not support overflow tells that I have to use vertical, but I want it horizontal.
How can I solve it? Any ideas or tricks?
The detail band in horizontal reports is not allowed to stretch vertically, so you need to make it tall enough to fit the subreport.
In your report, the subreport element in the master report has height=120. But the subreport has detail band with height=130, plus 20 pixels top margin and 20 bottom margin. So the subreport actually takes 170 pixels in height.
If you set the height of the subreport element in the master report to 170 and the height of the master detail band to 220, it will work with horizontal print order.
I have googled and prepared my sample report as per the given steps.
Steps:
Create sub report with variable retval_sub [kept default value to the variable as Hai]
Create main report variable retval_main.
Sub report properties --> added sub report variable as retval_sub and corresponding main report variable is retval_main.
I tried many times but it is not working i kept calculation type as System and Nothing also but it is not working for both.
Main report:
<?xml version="1.0" encoding="UTF-8"?>
<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="testing_ret_val" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5c1d1561-8eed-47a8-89c8-3cd1946ce07a">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["E:\\ilaiyaraja\\"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from my_table]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<variable name="retval_main" class="java.lang.String" calculation="System"/>
<detail>
<band height="43" splitType="Stretch"/>
</detail>
<summary>
<band height="226" splitType="Stretch">
<textField>
<reportElement x="31" y="173" width="100" height="20" uuid="4e5ed8fa-e4f6-42bc-8651-6888d79f01b5"/>
<textFieldExpression><![CDATA[$V{retval_main}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="15" y="16" width="200" height="100" uuid="2bd63504-b57e-4561-b527-62f6ffe46a30"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue subreportVariable="retval_sub" toVariable="retval_main"/>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "testing_ret_val_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</summary>
</jasperReport>
Sub Report:
<?xml version="1.0" encoding="UTF-8"?>
<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="testing_ret_val_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="822d1131-8494-45f3-a9ab-39fc9a05072f">
<queryString>
<![CDATA[select id from my_table]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<variable name="retval_sub" class="java.lang.String">
<variableExpression><![CDATA["Hai"]]></variableExpression>
</variable>
<detail>
<band height="45" splitType="Stretch">
<textField>
<reportElement x="107" y="17" width="100" height="20" uuid="f8d1612a-06be-4082-b915-0df82b3faa42"/>
<textFieldExpression><![CDATA[$V{retval_sub}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Please suggest
<subreport>
<reportElement x="-6" y="0" width="570" height="59" uuid="ac54a12b-8022-49a1-bc90-90cff664e3a1"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("footer")]]></dataSourceExpression>
<subreportExpression><![CDATA["footer.jrxml"]]></subreportExpression>
</subreport>
add this to your code, it will work
With the help of iReport 5.6.0 tool, I have created a master report. Then I have drag and drop a subreport to the repot group band of the master report. I have defined the SQL query and set the key and value via wizard. After that I have added a pie chart to the subreport.
When I run the subreport individually, it works fine with the provided SQL query. But when I run the master report via DynamicReports with Java code, it seems that the query does not work and return null values. As a result, no chart is displayed.
Is there any missing steps in my approach? Do I need to map/link somehow the subreport query results to master report?
Master report jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<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="templatedesign2" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="575" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10" uuid="8c9654e9-6770-46c4-a4d0-4bdf99195b70">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["D:\\DynamicReports\\src\\subreport\\"]]></defaultValueExpression>
</parameter>
<field name="item" class="java.lang.String"/>
<field name="reportTitle" class="java.lang.String"/>
<field name="customerName" class="java.lang.String"/>
<group name="Intro">
<groupHeader>
<band height="255">
<subreport isUsingCache="false">
<reportElement x="0" y="160" width="575" height="77" uuid="eb90e8b6-2860-4c94-ad10-3eb5031502fc"/>
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "templatereport2_subreport3.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
</jasperReport>
subreport jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<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="templatereport2_subreport3" pageWidth="555" pageHeight="802" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isTitleNewPage="true" uuid="3dc0ebf2-660d-4d0c-af85-ccae1f01bdee">
<parameter name="runCycleId" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT
count(status) AS count,
case when status=TRUE then 'Succeeded'else 'Failed'end AS status
FROM
"dbtable" dbtable
WHERE
id = 157
GROUP BY
status]]>
</queryString>
<field name="count" class="java.lang.Long"/>
<field name="status" class="java.lang.String"/>
<title>
<band height="351" splitType="Stretch">
<pie3DChart>
<chart evaluationTime="Report">
<reportElement x="20" y="22" width="415" height="244" uuid="a43afa44-c4e5-4ad5-b06e-8922128bcdaf"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<keyExpression><![CDATA[$F{status}]]></keyExpression>
<valueExpression><![CDATA[$F{count}]]></valueExpression>
</pieDataset>
<pie3DPlot>
<plot/>
<itemLabel/>
</pie3DPlot>
</pie3DChart>
<textField>
<reportElement x="134" y="292" width="100" height="20" uuid="2726affe-1fef-45a1-abc8-8da8c9856e42"/>
<textFieldExpression><![CDATA[$F{count}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="20" y="292" width="100" height="20" uuid="fa4e41c0-b4f4-443c-ab9e-3cf048a3f520"/>
<textFieldExpression><![CDATA[$F{status}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
Can you please advise?
Since you are using a query in the subreport you should pass the connection, not the datasource to it.
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
In your example
<subreport isUsingCache="false">
reportElement x="0" y="160" width="575" height="77" uuid="eb90e8b6-2860-4c94-ad10-3eb5031502fc"/>
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "templatereport2_subreport3.jasper"]]></subreportExpression>
</subreport>
I have generated a report (with JasperReport). My problem that the chart repeats, I have one chart and the report contains 22 pages! What is the problem?
This is my report:
<?xml version="1.0" encoding="UTF-8"?>
<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="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="New Dataset 1">
<parameter name="SQL" class="java.lang.String"/>
<parameter name="Titre" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[$P!{SQL}]]>
</queryString>
<field name="nb" class="java.lang.Long"/>
<field name="champ1" class="java.lang.String"/>
<field name="champ2" class="java.lang.String"/>
</subDataset>
<parameter name="SQL" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="Titre" class="java.lang.String"/>
<queryString>
<![CDATA[select id from jiraissue]]>
</queryString>
<field name="id" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="46" splitType="Stretch">
<textField>
<reportElement x="89" y="15" width="180" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P{Titre}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="13" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="185" splitType="Stretch">
<stackedBar3DChart>
<chart>
<reportElement x="57" y="16" width="420" height="165"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="New Dataset 1">
<datasetParameter name="SQL">
<datasetParameterExpression><![CDATA[$P{SQL}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA[$F{champ2}]]></seriesExpression>
<categoryExpression><![CDATA[$F{champ1}]]></categoryExpression>
<valueExpression><![CDATA[$F{nb}]]></valueExpression>
</categorySeries>
</categoryDataset>
<bar3DPlot>
<plot/>
<itemLabel color="#000000" backgroundColor="#FFFFFF"/>
<categoryAxisFormat>
<axisFormat>
<labelFont/>
<tickLabelFont/>
</axisFormat>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat>
<labelFont/>
<tickLabelFont/>
</axisFormat>
</valueAxisFormat>
</bar3DPlot>
</stackedBar3DChart>
</band>
</detail>
<columnFooter>
<band height="24" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="20" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="22" splitType="Stretch"/>
</summary>
Update
I have solved the problem by moving the chart to the summary part :)
In Jasper Report, everything you place in the detail band is repeated number of times it appears in the source.
If you want to show anything (not only chart) just once, avoid the detail band.
For example, you can place it in the summary section.
Update: As others pointed, I have extended my answer a little bit.
I also had face with the same problem like this before. It is because your data will be looped which causes such redundant of data. What you need to do is go to 'Print when expression' in properties and set your variable report count to 1. This is how it looks, $V{REPORT_COUNT}==1. It will display only once in your report.
I use $V{PAGE_NUMBER} == 1 as value of 'Print when expression' so it is forced to appear only on first page.