È abbastanza semplice risolvere il problema. È necessario creare e utilizzare una nuova variabile per sommare i valori della colonna "Pagamento medico".
Nel tuo caso la variabile può essere dichiarata in questo modo:
<variable name="total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{payment}]]></variableExpression>
</variable>
- il tipo di calcolo è Somma;
- il Reset tipo è Rapporto;
- l'variabile espressione è $ F {} pagamento, dove $ F {} pagamento è il nome di un campo contiene somma (dottore pagamento).
L'esempio di lavoro.
CSV di origine dati:
doctor_id,payment
A1,123
B1,223
C2,234
D3,678
D1,343
Il modello:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ...>
<queryString>
<![CDATA[]]>
</queryString>
<field name="doctor_id" class="java.lang.String"/>
<field name="payment" class="java.lang.Integer"/>
<variable name="total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{payment}]]></variableExpression>
</variable>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Doctor ID]]></text>
</staticText>
<staticText>
<reportElement x="100" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Doctor Payment]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement/>
<textFieldExpression><![CDATA[$F{doctor_id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement/>
<textFieldExpression><![CDATA[$F{payment}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Total]]></text>
</staticText>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement>
<font isBold="true" isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{total}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
Il risultato sarà:
È possibile trovare molte informazioni nello JasperReports Ultimate Guide.
fonte
2012-11-25 15:57:48
Ho un po 'di logica, ma dove mettere una nuova variabile, sto mettendo in partenza, vale a dire dopo molti dichiarati, ma fornire l'errore che la variabile non è stata trovata: "totale" –
@SagarNikam Hai provato il mio esempio? –
sì, signore con il tuo campione funziona, ma passo a dati in tempo reale, lavorando con mysql query, dà errore "variabile non trovata", dichiaro variabile dopo queryString> sopra, potrei inviare file completo –