Jump to content

Create Sub report using Jasper API


dheeraj.madhu
Go to solution Solved by dheeraj.madhu,

Recommended Posts

I am able to create a Master report using Jasper API. However stuck in designing a sub report using Jasper API and add it into Master report design.

 

Master Report JRXML

 

<band height="250" splitType="Stretch">

    <subreport>

        <reportElement isPrintRepeatedValues="false" x="0" y="0" width="550" height="233" isRemoveLineWhenBlank="true" backcolor="#000000"></reportElement>

        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{time})]]></dataSourceExpression>

        <subreportExpression><![CDATA["subreport.jasper"]]></subreportExpression>

    </subreport>

</band>

 

Sub Report JRXML

 

<field name="count" class="java.lang.String"/>

<field name="timeStamp" class="java.lang.String"/>

<group name="ProductGroup">

    <groupExpression><![CDATA[$F{count}]]></groupExpression>

    <groupHeader>

        <band height="250">

            <timeSeriesChart>

                <chart evaluationTime="Report">

                    <reportElement x="0" y="25" width="550" height="175"/>

                    <chartTitle/>

                    <chartSubtitle/>

                    <chartLegend/>

                </chart>

                <timeSeriesDataset timePeriod="Minute">

                    <dataset incrementType="None"/>

                    <timeSeries>

                        <seriesExpression><![CDATA["Count"]]></seriesExpression>

                        <timePeriodExpression><![CDATA[new Date(Long.valueOf($F{timeStamp})*1000)]]></timePeriodExpression>

                        <valueExpression><![CDATA[integer.valueOf($F{count})]]></valueExpression>

                    </timeSeries>

                </timeSeriesDataset>

                <timeSeriesPlot isShowLines="true" isShowShapes="false">

                    <plot/>

                    <timeAxisFormat>

                        <axisFormat>

                            <labelFont/>

                            <tickLabelFont/>

                        </axisFormat>

                    </timeAxisFormat>

                    <valueAxisFormat>

                        <axisFormat>

                            <labelFont/>

                            <tickLabelFont/>

                        </axisFormat>

                    </valueAxisFormat>

                </timeSeriesPlot>

            </timeSeriesChart> 

        </band>

    </groupHeader>

</group>

These Stand alone XML's getting compiled and will generate report.

 

However I want to create these using Jasper Report API. I have Just started. But stuck without any example available.

 

JRDesignSubreport jSubreport = new JRDesignSubreport(jasperDesign); jSubreport.setUsingCache(false); jSubreport.setRemoveLineWhenBlank(true);
JRDesignExpression subReportDataSourceExpr = new JRDesignExpression();subReportDataSourceExpr.addResourceChunk("");//How to set List Data Source?JRDesignSubreportParameter subReportDataSource = new JRDesignSubreportParameter();subReportDataSource.setExpression(subReportDataSourceExpr);jSubreport.setDataSourceExpression(subReportDataSourceExpr);
//How to Add <subreportExpression><![CDATA["subreport.jasper"]]></subreportExpression>[/code]
 

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

Ok. Issue is solved.

Here is the code block

band = new JRDesignBand();band.setHeight(250);band.setSplitType(SplitTypeEnum.STRETCH);JRDesignSubreport jSubreport = new JRDesignSubreport(jasperDesign);jSubreport.setUsingCache(false);jSubreport.setRemoveLineWhenBlank(true);jSubreport.setPrintRepeatedValues(false);JRDesignExpression expression = new JRDesignExpression();expression.setText("new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{time})");jSubreport.setDataSourceExpression(expression);expression = new JRDesignExpression();expression.setText(""/path/to/sub.jasper"");jSubreport.setExpression(expression);band.addElement(jSubreport);[/code]

 

Link to comment
Share on other sites

  • 9 months later...
  • 1 year later...

band = new JRDesignBand();

band.setHeight(250);

band.setSplitType(SplitTypeEnum.STRETCH);

 

JRDesignSubreport jSubreport = new JRDesignSubreport(jasperDesign);

jSubreport.setUsingCache(false);

jSubreport.setRemoveLineWhenBlank(true);

jSubreport.setPrintRepeatedValues(false);

 

JRDesignExpression expression = new JRDesignExpression();

expression.setText("new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{time})");

jSubreport.setDataSourceExpression(expression);

 

expression = new JRDesignExpression();

expression.setText(""/path/to/sub.jasper"");

 

jSubreport.setExpression(expression);

band.addElement(jSubreport);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...