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>