title: Create sub report using JasperReports API
body: <p>I am able to create a Master report using <em>JasperReports API</em>. However stuck in designing a sub report using <em>JasperReports API</em> and add it into Master report design.</p>
  
  <p>Master Report JRXML</p>
  
  <pre><code>    &lt;band height="250" splitType="Stretch"&gt;
          &lt;subreport&gt;
          &lt;reportElement isPrintRepeatedValues="false" x="0" y="0" width="550" height="233" isRemoveLineWhenBlank="true" backcolor="#000000"&gt;
          &lt;/reportElement&gt;
          &lt;dataSourceExpression&gt;&lt;![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{time})]]&gt;   
  &lt;/dataSourceExpression&gt;
          &lt;subreportExpression&gt;&lt;![CDATA["subreport.jasper"]]&gt;&lt;/subreportExpression&gt;
      &lt;/subreport&gt;
     &lt;/band&gt;
  </code></pre>
  
  <p>Sub Report JRXML</p>
  
  <pre><code>&lt;field name="count" class="java.lang.String"/&gt;
  &lt;field name="timeStamp" class="java.lang.String"/&gt;
  &lt;group name="ProductGroup"&gt;
      &lt;groupExpression&gt;&lt;![CDATA[$F{count}]]&gt;&lt;/groupExpression&gt;
      &lt;groupHeader&gt;
          &lt;band height="250"&gt;
              &lt;timeSeriesChart&gt;
                  &lt;chart evaluationTime="Report"&gt;
                      &lt;reportElement x="0" y="25" width="550" height="175"/&gt;
                      &lt;chartTitle/&gt;
                      &lt;chartSubtitle/&gt;
                      &lt;chartLegend/&gt;
                  &lt;/chart&gt;
                  &lt;timeSeriesDataset timePeriod="Minute"&gt;
                      &lt;dataset incrementType="None"/&gt;
                      &lt;timeSeries&gt;
                          &lt;seriesExpression&gt;&lt;![CDATA["Count"]]&gt;&lt;/seriesExpression&gt;
                          &lt;timePeriodExpression&gt;&lt;![CDATA[new Date(Long.valueOf($F{timeStamp})*1000)]]&gt;&lt;/timePeriodExpression&gt;
                          &lt;valueExpression&gt;&lt;![CDATA[Integer.valueOf($F{count})]]&gt;&lt;/valueExpression&gt;
                      &lt;/timeSeries&gt;
                  &lt;/timeSeriesDataset&gt;
                  &lt;timeSeriesPlot isShowLines="true" isShowShapes="false"&gt;
                      &lt;plot/&gt;
                      &lt;timeAxisFormat&gt;
                          &lt;axisFormat&gt;
                              &lt;labelFont/&gt;
                              &lt;tickLabelFont/&gt;
                          &lt;/axisFormat&gt;
                      &lt;/timeAxisFormat&gt;
                      &lt;valueAxisFormat&gt;
                          &lt;axisFormat&gt;
                              &lt;labelFont/&gt;
                              &lt;tickLabelFont/&gt;
                          &lt;/axisFormat&gt;
                      &lt;/valueAxisFormat&gt;
                  &lt;/timeSeriesPlot&gt;
              &lt;/timeSeriesChart&gt; 
          &lt;/band&gt;
      &lt;/groupHeader&gt;
  &lt;/group&gt;
  </code></pre>
  
  <p>These Stand alone XML's getting compiled and will generate report.</p>
  
  <p>However i want to create these using Jasper Report API.
  I have Just started. But stuck without any example available.</p>
  
  <pre><code>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 &lt;subreportExpression&gt;&lt;![CDATA["subreport.jasper"]]&gt;&lt;/subreportExpression&gt;
  </code></pre>