Jasper Report graph in iReport repeating

chartsireportjasper-reports

I have a line graph in iReport which is incrementally repeating in every page, that is, if the graph has 30 x/y pairs (this is dynamic), the report will have 30 pages, of which the first will have just one value, the 2nd two values, and so on. Only the last one will contain the complete graph.

Questions "chart repeat many time" and "Problem with charting using JasperReport" and "How to print the grand total only in the last page of a very long report?" did not solve my problem. I understand that putting the chart in the Detail section makes the chart repeat, but putting it in the Summary, Footer, lastPageFooter, Title, etc. sections makes it display only one value. Same when I put it in the Detail section and use <printWhenExpression>.

My code:

<?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="nodes-allarmipersistenti" 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="0"/>
    <field name="day" class="java.lang.Number"/>
    <field name="month" class="java.lang.String"/>
    <field name="year" class="java.lang.String"/>
    <field name="dsunita" class="java.lang.String"/>
    <field name="valueNumber" class="java.lang.Number"/>
    <field name="logo" class="java.lang.String"/>
    <field name="today" class="java.lang.String"/>
    <field name="option" class="java.lang.String"/>
    <title>
        <band height="89">
            <staticText>
                <reportElement mode="Opaque" x="0" y="67" width="424" height="22" backcolor="#CCFFFF"/>
                <textElement textAlignment="Right" verticalAlignment="Middle" markup="none">
                    <font size="10" isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[GRAFICO PARAMETRO]]></text>
            </staticText>
            <staticText>
                <reportElement x="600" y="0" width="100" height="38"/>
                <textElement verticalAlignment="Middle"/>
                <text><![CDATA[Stampato in data]]></text>
            </staticText>
            <textField>
                <reportElement x="700" y="0" width="102" height="38"/>
                <textElement textAlignment="Right" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{today}]]></textFieldExpression>
            </textField>
            <image>
                <reportElement x="0" y="0" width="100" height="67"/>
                <imageExpression><![CDATA[$F{logo}]]></imageExpression>
            </image>
            <staticText>
                <reportElement x="700" y="38" width="102" height="29"/>
                <textElement textAlignment="Right"/>
                <text><![CDATA[MaRe - Telecontrollo]]></text>
            </staticText>
            <textField>
                <reportElement mode="Opaque" x="424" y="67" width="378" height="22" backcolor="#CCFFFF"/>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[' ' + $F{option}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <lastPageFooter>
        <band height="387" splitType="Stretch">
            <xyLineChart>
                <chart evaluationTime="Page">
                    <reportElement x="0" y="0" width="802" height="387"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <xyDataset>
                    <dataset incrementType="Report"/>
                    <xySeries>
                        <seriesExpression><![CDATA["Unità " + $F{dsunita}]]></seriesExpression>
                        <xValueExpression><![CDATA[$F{day}]]></xValueExpression>
                        <yValueExpression><![CDATA[$F{valueNumber}]]></yValueExpression>
                    </xySeries>
                </xyDataset>
                <linePlot>
                    <plot/>
                </linePlot>
            </xyLineChart>
        </band>
    </lastPageFooter>
</jasperReport>

Datasource here is a JRBeanCollectionDataSource.

Best Answer

Putting it in the Detail band is wrong (as you noticed). Putting it in the Title or Summary will work. Your choice of evaluationTime="Page" doesn't look right. Try changing this to evaluationTime="Report"

Related Topic