如何在列标题中显示列的总和? [英] How can I show sum of columns in column header?
问题描述
我必须在iReport 5工具中设计一个Jasper报告,其中包含以下约束:
- 我需要显示每列的总和在图片中的标题中
- 我需要像图片一样显示垂直列
期望输出
是否可以设计这样的报告?
使用正常 detail
band和 columnHeader
这是通过使用 calculateType =sum<创建变量来实现的/ code>在您想要汇总的字段上
请参阅:
I have to design a Jasper report in iReport 5 tool with the following constraints:
- I need to show the sum of each column in the header like in the image
- I need to show the columns vertical like in the image
Desired output
Is it possible to design report like this?
Using the normal detail
band and columnHeader
band this is achieved by creating a variable with calculationType="sum"
on the field you like to sum
See: How to sum all values in a column in Jaspersoft iReport Designer?
Then display the variable using a textField
in the columnHeader
band, setting evaluationTime="Report"
so that variable is calculated before displaying it.
To rotate a textElement
vertical use the rotation
attribute (rotation="Left"
)
Example:
<?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="ReportTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="43c90ca5-f3c3-4dda-8423-9ff1442f90e3">
<queryString>
<![CDATA[select * from mytable]]>
</queryString>
<field name="descr" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="value" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="sumValue" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{value}]]></variableExpression>
</variable>
<columnHeader>
<band height="70">
<textField>
<reportElement mode="Opaque" x="0" y="50" width="100" height="20" forecolor="#000000" backcolor="#CCCCCC" uuid="dfe13f55-12a6-4c33-b5ba-00dd61f37c96"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["TOTALE"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report" pattern="###0.00;-###0.00">
<reportElement mode="Opaque" x="100" y="50" width="100" height="20" forecolor="#000000" backcolor="#CCCCCC" uuid="ed251db0-474e-4e20-8788-3c2f08bfd1e7"/>
<box leftPadding="2" rightPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{sumValue}]]></textFieldExpression>
</textField>
<staticText>
<reportElement mode="Opaque" x="100" y="0" width="100" height="50" forecolor="#000000" backcolor="#CCCCCC" uuid="62b62711-8cfb-4df2-8f9e-4a34249dcc66"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="Left">
<font size="8"/>
</textElement>
<text><![CDATA[SESSIONS]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Immediate">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="6a009a8c-16de-451c-a0f1-516a48f793d0"/>
<box leftPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{descr}]]></textFieldExpression>
</textField>
<textField pattern="###0.00;-###0.00">
<reportElement x="100" y="0" width="100" height="20" uuid="1fccff95-408c-4364-b003-c691fefdde62"/>
<box rightPadding="2">
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Result (with some arbitrary data)
这篇关于如何在列标题中显示列的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!