JasperReports:创建 table 尝试使用不带列组的 CrossTab 时出错

JasperReports: Error creating table trying to use CrossTab without column group

我想知道是否有办法使用 JapserReports CrossTab 以任何其他方式制作像这样 的 table 其中行组是字段 value7.

使用的数据集是JRBeanCollectionDataSource(list of SubViews)

其中 SubView 是:

public class SubView{

  //...

  private String value1;
  private String value2;
  private String value3;
  private String value4;
  private String value5;
  private String value6;
  private String value7;

  //...getters and setters...
}

注意这里不需要column group,但是如果我不配置column group,jasper编译不成功(报错信息:Crosstab should have at least one column group

这对我来说似乎不是 crosstab 问题。 Crosstab 在列为 动态 时使用,因此您的错误消息

Crosstab should have at least one column group.

因为有 "no need of a column group" 结果是在 value7 上使用正常的 detail bandgrouping 获得的结果。

因此,在将标签放入 columnHeader 并将值 1-6 放入 detail band 之后,您可以在 value7 上添加一个 groupHeader

的分组

示例(我只在 detail band 中包含直到值 3 以对答案进行排序

<?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="report2" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="8944f542-2955-4224-933c-5a87fd36f527">
<queryString>
    <![CDATA[]]>
</queryString>
<field name="value1" class="java.lang.String"/>
<field name="value2" class="java.lang.String"/>
<field name="value3" class="java.lang.String"/>
<field name="value7" class="java.lang.String"/>
<group name="Value7">
    <groupExpression><![CDATA[$F{value7}]]></groupExpression>
    <groupHeader>
        <band height="21">
            <textField>
                <reportElement x="0" y="0" width="300" height="20" uuid="208ca6e5-b396-47cb-858b-71039f5bdf7a"/>
                <textFieldExpression><![CDATA["Value 7: " + $F{value7}]]></textFieldExpression>
            </textField>
        </band>
    </groupHeader>
</group>
<background>
    <band/>
</background>
<columnHeader>
    <band height="50">
        <staticText>
            <reportElement x="0" y="30" width="100" height="20" uuid="edf0f0f1-c979-4d20-987e-e8decb0b584a"/>
            <text><![CDATA[value1]]></text>
        </staticText>
        <staticText>
            <reportElement x="100" y="30" width="100" height="20" uuid="4287323f-e6d3-40d8-a2d4-44981bfa5c59"/>
            <text><![CDATA[value2]]></text>
        </staticText>
        <staticText>
            <reportElement x="200" y="30" width="100" height="20" uuid="b9aa7dfd-edd8-439b-b4c7-12916a740da8"/>
            <text><![CDATA[value3]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="24">
        <textField>
            <reportElement x="0" y="0" width="100" height="20" uuid="2bcc436d-4c3a-4db1-a2ea-87edf92af98f"/>
            <textFieldExpression><![CDATA[$F{value1}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="100" y="0" width="100" height="20" uuid="f893721e-1aa6-44ca-9a9a-ac795ff63a0a"/>
            <textFieldExpression><![CDATA[$F{value2}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="200" y="0" width="100" height="20" uuid="36ad9612-620b-4eec-9608-f26b5306b01a"/>
            <textFieldExpression><![CDATA[$F{value3}]]></textFieldExpression>
        </textField>
    </band>
</detail>
</jasperReport>

如果你喜欢使用交叉表,你需要以不同的方式设置你的数据集(因为列也变成动态的)查看这个示例:crosstab example