dheeraj.madhu Posted May 9, 2014 Share Posted May 9, 2014 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 More sharing options...
Solution dheeraj.madhu Posted May 9, 2014 Author Solution Share Posted May 9, 2014 Ok. Issue is solved.Here is the code blockband = 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 More sharing options...
krishnarhl Posted February 11, 2015 Share Posted February 11, 2015 How did you solve it? Link to comment Share on other sites More sharing options...
neha.pateliya25 Posted September 27, 2016 Share Posted September 27, 2016 How to do it?Can you please explain? Link to comment Share on other sites More sharing options...
dheeraj.madhu Posted September 29, 2016 Author Share Posted September 29, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now