2012-03-13 91 views
1

我已經創建了一個表格報告。爲每個報告重複行

我已經把noagency nameyear 1year 2year 3year 4year 5總第一行和第二行。我已將year 1,year 2,year 3,year 4,year 5以及Detail頻段中的所有機構的總和。之後,我把折線圖佈局。最後,我把page break$V{REPORT_COUNT} % 5==0條件。但問題是這兩行都有重複的數據。如何解決這個問題呢?我想爲每個報告查看每頁5行。結果仍然是一樣的。

在這裏,我附上我的代碼:

更新:

<?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="charttest" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" 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="99"/> 
    <parameter name="P_YEAR" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[]]></defaultValueExpression> 
    </parameter> 
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> 
     <defaultValueExpression><![CDATA["C:\\Documents and Settings\\NT\\Desktop\\CHART\\"]]></defaultValueExpression> 
    </parameter> 

    <field name="PARENT_NAME" class="java.lang.String"/> 
    <field name="PARENT_NAME_SECTOR" class="java.lang.String"/> 
    <field name="AGENCY_PARENT_CODE" class="java.lang.String"/> 
    <field name="AGENCY_CODE" class="java.lang.String"/> 
    <field name="AGENCY_NAME" class="java.lang.String"/> 
    <field name="YEAR" class="java.math.BigDecimal"/> 
    <field name="SECTOR_ID" class="java.lang.String"/> 
    <field name="SECTOR_NAME" class="java.lang.String"/> 
    <field name="DYEAR1" class="java.math.BigDecimal"/> 
    <field name="DYEAR2" class="java.math.BigDecimal"/> 
    <field name="DYEAR3" class="java.math.BigDecimal"/> 
    <field name="DYEAR4" class="java.math.BigDecimal"/> 
    <field name="DYEAR5" class="java.lang.String"/> 
    <field name="YR1" class="java.math.BigDecimal"/> 
    <field name="YR2" class="java.math.BigDecimal"/> 
    <field name="YR3" class="java.math.BigDecimal"/> 
    <field name="YR4" class="java.math.BigDecimal"/> 
    <field name="YR5" class="java.math.BigDecimal"/> 
    <variable name="YR1_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR1}]]></variableExpression> 
    </variable> 
    <variable name="YR2_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR2}]]></variableExpression> 
    </variable> 
    <variable name="YR3_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR3}]]></variableExpression> 
    </variable> 
    <variable name="YR4_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR4}]]></variableExpression> 
    </variable> 
    <variable name="YR5_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR5}]]></variableExpression> 
    </variable> 
    <variable name="YR1_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR1}]]></variableExpression> 
    </variable> 
    <variable name="YR2_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR2}]]></variableExpression> 
    </variable> 
    <variable name="YR3_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR3}]]></variableExpression> 
    </variable> 
    <variable name="YR4_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR4}]]></variableExpression> 
    </variable> 
    <variable name="YR5_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR5}]]></variableExpression> 
    </variable> 
    <variable name="sumA" class="java.lang.Integer" calculation="Sum"> 
     <variableExpression><![CDATA[$F{YR1}+$F{YR2}+$F{YR3}+$F{YR4}+$F{YR5}]]></variableExpression> 
    </variable> 
    <group name="Agency"> 
     <groupExpression><![CDATA[$F{PARENT_NAME_SECTOR}]]></groupExpression> 
     <groupHeader> 
      <band height="192"> 
       <textField> 
        <reportElement x="622" y="83" width="100" height="20"/> 
        <textElement/> 
        <textFieldExpression><![CDATA[$F{SECTOR_NAME}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="64" y="145" width="100" height="20"/> 
        <textElement/> 
        <textFieldExpression><![CDATA[$F{AGENCY_NAME}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="74" y="83" width="100" height="20"/> 
        <textElement/> 
        <textFieldExpression><![CDATA[$F{DYEAR1}]]></textFieldExpression> 
       </textField> 
       <staticText> 
        <reportElement x="18" y="83" width="56" height="20"/> 
        <textElement/> 
        <text><![CDATA[Year From :]]></text> 
       </staticText> 
       <staticText> 
        <reportElement x="18" y="104" width="56" height="20"/> 
        <textElement/> 
        <text><![CDATA[Year To :]]></text> 
       </staticText> 
       <staticText> 
        <reportElement x="574" y="83" width="48" height="20"/> 
        <textElement/> 
        <text><![CDATA[Sector :]]></text> 
       </staticText> 
       <staticText> 
        <reportElement x="18" y="145" width="46" height="20"/> 
        <textElement/> 
        <text><![CDATA[Agency :]]></text> 
       </staticText> 
       <textField> 
        <reportElement x="74" y="104" width="100" height="20"/> 
        <textElement/> 
        <textFieldExpression><![CDATA[$F{DYEAR5}]]></textFieldExpression> 
       </textField> 
       <staticText> 
        <reportElement x="0" y="21" width="802" height="26"/> 
        <textElement textAlignment="Center" verticalAlignment="Middle"/> 
        <text><![CDATA[5 YEAR STATISTICS ON APPLICATION RECEIVED (BY ALL AGENCIES)]]></text> 
       </staticText> 
       <staticText> 
        <reportElement x="18" y="165" width="33" height="27"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center" verticalAlignment="Middle"/> 
        <text><![CDATA[No.]]></text> 
       </staticText> 
       <textField> 
        <reportElement x="425" y="178" width="85" height="14"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$F{DYEAR3}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="510" y="178" width="85" height="14"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$F{DYEAR4}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="595" y="178" width="85" height="14"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$F{DYEAR5}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="340" y="178" width="85" height="14"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$F{DYEAR2}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="255" y="178" width="85" height="14"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$F{DYEAR1}]]></textFieldExpression> 
       </textField> 
       <staticText> 
        <reportElement x="255" y="165" width="425" height="13"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <text><![CDATA[Year]]></text> 
       </staticText> 
       <staticText> 
        <reportElement x="51" y="165" width="204" height="27"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center" verticalAlignment="Middle"/> 
        <text><![CDATA[Agency Name]]></text> 
       </staticText> 
       <staticText> 
        <reportElement x="680" y="165" width="85" height="27"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <text><![CDATA[Total]]></text> 
       </staticText> 
      </band> 
     </groupHeader> 
     <groupFooter> 
      <band height="395"> 
       <lineChart> 
        <chart> 
         <reportElement x="30" y="42" width="772" height="353"/> 
         <chartTitle/> 
         <chartSubtitle/> 
         <chartLegend/> 
        </chart> 
        <categoryDataset> 
         <dataset resetType="Group" resetGroup="Agency" incrementType="Report"/> 
         <categorySeries> 
          <seriesExpression><![CDATA[$F{PARENT_NAME_SECTOR}]]></seriesExpression> 
          <categoryExpression><![CDATA[$F{YEAR}]]></categoryExpression> 
          <valueExpression><![CDATA[$F{YR5}]]></valueExpression> 
         </categorySeries> 
        </categoryDataset> 
        <linePlot> 
         <plot/> 
        </linePlot> 
       </lineChart> 
       <textField> 
        <reportElement x="340" y="0" width="85" height="20"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$V{YR2_2}]]></textFieldExpression> 
       </textField> 
       <staticText> 
        <reportElement x="18" y="0" width="237" height="20"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <text><![CDATA[                   Total]]></text> 
       </staticText> 
       <textField> 
        <reportElement x="255" y="0" width="85" height="20"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$V{YR1_2}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="425" y="0" width="85" height="20"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$V{YR3_2}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="510" y="0" width="85" height="20"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$V{YR4_2}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="595" y="0" width="85" height="20"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[$V{YR5_2}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="680" y="0" width="85" height="20"/> 
        <box> 
         <pen lineWidth="0.5"/> 
         <topPen lineWidth="0.5"/> 
         <leftPen lineWidth="0.5"/> 
         <bottomPen lineWidth="0.5"/> 
         <rightPen lineWidth="0.5"/> 
        </box> 
        <textElement textAlignment="Center"/> 
        <textFieldExpression><![CDATA[new Integer($V{YR1_1}.intValue() + $V{YR2_1}.intValue()+ 
$V{YR3_1}.intValue()+ $V{YR4_1}.intValue())+ $V{YR5_1}.intValue()]]></textFieldExpression> 
       </textField> 
      </band> 
     </groupFooter> 
    </group> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <detail> 
     <band height="20" splitType="Stretch"> 
      <textField> 
       <reportElement x="510" y="0" width="85" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression><![CDATA[$F{YR4}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="51" y="0" width="204" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{PARENT_NAME_SECTOR}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="18" y="0" width="33" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression><![CDATA[$V{COLUMN_COUNT}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="255" y="0" width="85" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression><![CDATA[$F{YR1}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="340" y="0" width="85" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression><![CDATA[$F{YR2}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="425" y="0" width="85" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression><![CDATA[$F{YR3}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="595" y="0" width="85" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression><![CDATA[$F{YR5}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="680" y="0" width="85" height="20"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression><![CDATA[new Integer($F{YR1}.intValue() + $F{YR2}.intValue()+ $F{YR3}.intValue()+ $F{YR4}.intValue())+ $F{YR5}.intValue()]]></textFieldExpression> 
      </textField> 
      <break> 
       <reportElement x="0" y="19" width="802" height="1"> 
        <printWhenExpression><![CDATA[($V{REPORT_COUNT} % 5 == 0)]]></printWhenExpression> 
       </reportElement> 
      </break> 
     </band> 
    </detail> 
</jasperReport> 
+0

您可以發佈報告設計(在iReport中)和jrxml文件的屏幕截圖嗎? – 2012-03-13 11:26:14

+0

那麼'Designer'視圖的截圖呢? – 2012-03-13 11:42:49

+0

你期待什麼結果? – 2012-03-13 12:06:04

回答

0

如果我理解正確的話,你想擁有5個明細行之後的圖形,然後越線?這種情況不會發生的原因是因爲你在每一個細節行之後都有線條打印。所以它從來沒有真正擊中第五排。您需要將折線圖移至agnesi Group Footer 1部分。

UPDATE:如果你只想在第一頁上的列標題,那麼你需要一個printWhenExpression添加到它有$V{PAGE_NUMBER}==1

月2日更新:你有幾件事錯了你的報告。

  • 你在頁面頁腳中放置了一個分頁符。那裏不應該是 。由於在頁腳 中根本沒有分頁。
  • 兩個你有多個細節部分。我不認爲這是 工作你期望的方式。您的詳細信息2部分 中的項目可能多於Agency Group Footer 1否頁面 中斷
  • 三個列標題看起來不正確。你在那裏引用 字段。字段是您的數據源中的數據,其中 在組和明細部分中迭代。作爲最好的猜測,這個 應該被移入Agency Group Header 1而不是 列標題。
  • 最後,你應該把你的情況分頁的唯一地方是在 的Detail 1部分與打印時表達 ($V{REPORT_COUNT} % 5) == 0

東西我發現,幫助我讓事情變得更清晰是完全刪除的章節我沒有使用。一旦你完成了我告訴過你的事情,你可以刪除標題,頁眉,列標題,頁腳和摘要部分。

+0

感謝您的建議。我試過了,它成功了。但現在的問題是,當數據小於5時,它無法讀取最後一頁的數據。我認爲問題是「$ V {REPORT_COUNT}%5 == 0」。在這裏我附上了照片。在圖片中,我已將條件「$ V {REPORT_COUNT}%5 == 0」放入「Detail2」和「Group footer」中的「print When expression」中。 – 2012-03-14 01:44:38

+0

您可以顯示並告訴我或逐步如何正確安排報告。現在我的問題是報告少於5行時,不能顯示總數和折線圖。 ( – 2012-03-14 15:12:16

+0

)不,我還沒有發佈你的jrxml文件的內容,所以任何人都得看看鏈接到截圖鏈接對不起,請花一些時間,清理並整理上面的問題,並將jrxml的文本(不是截圖)放在問題中,也許有人可以幫助你自己,直到你付出更多的努力,可能是你自己的。 – 2012-03-14 15:16:00