0

我有几个子数据集,我使用图表的大部分结果和这个(工作)部分:

<pieDataset>
 <dataset incrementType="Group" incrementGroup="group_2113924770">
  <datasetRun subDataset="data_2113924770" uuid="724d6473-dd5d-41c4-af6e-4c5b1d995416">
   <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]>
   </connectionExpression>
  </datasetRun>
 </dataset>
</pieDataset>

SubDataset 定义如下所示:

<subDataset name="data_2113924770" uuid="4a29c5a4-cd0a-4078-8b88-6699c60cbe5e">
    <queryString language="MongoDbQuery">
        <![CDATA[{ collectionName: 'xxx',
               findQuery : { xxx: 1234 },
               sort: { geo.c: -1 }
             }]]>
    </queryString>
    <field name="xxx" class="java.lang.Integer"/>
    <field name="geo.c" class="java.lang.String"/>
    <variable name="var_2113924770" class="java.lang.Integer" resetType="Group" resetGroup="group_2113924770" calculation="Count">
        <variableExpression><![CDATA[$F{geo.c}]]></variableExpression>
    </variable>
    <filterExpression><![CDATA[$F{geo.c} != null]]></filterExpression>
    <group name="group_2113924770">
        <groupExpression><![CDATA[$F{geo.c}]]></groupExpression>
    </group>
</subDataset>

适用于图表(结果实际上是分组的)。现在我想在表格而不是图表中显示分组的 geo.c 数据,但输出如下所示:

在此处输入图像描述

这是使用相同数据集时我的图表的外观:

在此处输入图像描述

无法放入 <dataset incrementType="Group" incrementGroup="group_2113924770">表格,并且行没有按国家/地区分组。我尝试了“printRepeatedValues”选项但没有成功。我认为这是主要问题。

表中数据集的定义如下所示:

                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="data_2113924770" uuid="8c9a7682-73d6-4c85-b37d-5333eb7806cb">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>

在尝试放入dataset时,出现以下错误:

加载报告模板时出错:发现以“dataset”开头的无效内容,预期为“datasetRun”。

问题:如何避免重复键值,每个国家只有一次?

表定义:

<group name="presentation_2113924770" isStartNewPage="true">
    <groupExpression><![CDATA[null]]></groupExpression>
    <groupHeader>
        <band height="225">
            <componentElement>
                <reportElement uuid="59259048-375f-4d6e-8c64-803ed1d626e2" key="table 3" style="table 3" isPrintRepeatedValues="false" x="25" y="24" width="360" height="140" isRemoveLineWhenBlank="true"/>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="data_2113924770" uuid="3accd345-1640-4493-a8ae-d000f84ccfcd">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="90" uuid="de9563e1-11a3-4c60-80bd-5678a9232475">
                        <jr:tableHeader style="table 3_TH" height="30"/>
                        <jr:tableFooter style="table 3_TH" height="30"/>
                        <jr:columnHeader style="table 3_CH" height="30">
                            <staticText>
                                <reportElement uuid="91f39641-8c93-4cc0-92a9-01649f83991c" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Country]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:columnFooter style="table 3_CH" height="30"/>
                        <jr:detailCell style="table 3_TD" height="20">
                            <textField>
                                <reportElement uuid="f7e51c9f-7837-45de-b90a-daaa3c330c06" x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{geo.c}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90" uuid="9374f6e6-0dde-4699-bd4e-3479526babb4">
                        <jr:tableHeader style="table 3_TH" height="30"/>
                        <jr:tableFooter style="table 3_TH" height="30"/>
                        <jr:columnHeader style="table 3_CH" height="30">
                            <staticText>
                                <reportElement uuid="9e67b831-f794-4ead-ad33-fea93cc5ca63" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Hits]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:columnFooter style="table 3_CH" height="30"/>
                        <jr:detailCell style="table 3_TD" height="20">
                            <textField>
                                <reportElement uuid="e823f0ac-8c65-4bd9-b243-0a8335aacc4a" x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$V{var_2113924770}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </groupHeader>
</group>
4

2 回答 2

0

甚至 Crosstab 元素看起来也更复杂,它有自己的聚合,因此适用于我的情况。表不适用于子数据集。

在此处输入图像描述

这完美地完成了这项工作:

<crosstab>
                <reportElement uuid="d276ffa1-21e0-4ed8-8227-9655b60db25d" x="0" y="0" width="802" height="469"/>
                <crosstabDataset>
                    <dataset>
                        <datasetRun subDataset="data_1825349606" uuid="c6e653d6-3eba-4064-a26e-c08d0f036b21">
                            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        </datasetRun>
                    </dataset>
                </crosstabDataset>
                <rowGroup name="geo.c" width="334">
                    <bucket class="java.lang.String">
                        <bucketExpression><![CDATA[$F{geo.c}]]></bucketExpression>
                    </bucket>
                    <crosstabRowHeader>
                        <cellContents backcolor="#73B0E6" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#FFFFFF"/>
                            </box>
                            <textField>
                                <reportElement uuid="793c2a9e-5298-48c6-b15f-a1dd017bd781" style="Crosstab Data Text" x="0" y="0" width="70" height="25"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$V{geo.c}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabRowHeader>
                    <crosstabTotalRowHeader>
                        <cellContents/>
                    </crosstabTotalRowHeader>
                </rowGroup>
                <columnGroup name="var_1825349606" height="30">
                    <bucket class="java.lang.Integer">
                        <bucketExpression><![CDATA["test"]]></bucketExpression>
                    </bucket>
                    <crosstabColumnHeader>
                        <cellContents backcolor="#73B0E6" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#FFFFFF"/>
                            </box>
                            <textField>
                                <reportElement uuid="751c32bf-7945-4532-a155-1ad1f533b559" style="Crosstab Data Text" x="0" y="0" width="144" height="30"/>
                                <textElement>
                                    <font fontName="Verdana" size="12" isBold="true"/>
                                </textElement>
                                <textFieldExpression><![CDATA["Hits"]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabColumnHeader>
                    <crosstabTotalColumnHeader>
                        <cellContents/>
                    </crosstabTotalColumnHeader>
                </columnGroup>
                <measure name="geo.cMeasure" class="java.lang.Integer" calculation="Count">
                    <measureExpression><![CDATA[$F{geo.c}]]></measureExpression>
                </measure>
                <crosstabCell width="144" height="25">
                    <cellContents>
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#FFFFFF"/>
                        </box>
                        <textField>
                            <reportElement uuid="68daa770-9cc9-427f-a03a-9a614e585fb5" style="Crosstab Data Text" x="0" y="0" width="144" height="25"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{geo.cMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell height="25" rowTotalGroup="geo.c">
                    <cellContents backcolor="#CFDBE6" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#FFFFFF"/>
                        </box>
                        <textField>
                            <reportElement uuid="7a8a647f-84cd-4cff-84dc-bce867499f91" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{geo.cMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell width="50" columnTotalGroup="var_1825349606">
                    <cellContents backcolor="#CFDBE6" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#FFFFFF"/>
                        </box>
                        <textField>
                            <reportElement uuid="09274f02-3cc5-491e-922c-653f9a8908fe" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{geo.cMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell rowTotalGroup="geo.c" columnTotalGroup="var_1825349606">
                    <cellContents backcolor="#CFDBE6" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#FFFFFF"/>
                        </box>
                        <textField>
                            <reportElement uuid="2d2e463d-c66b-4575-a08d-42db590cd03d" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression>  <![CDATA[$V{geo.cMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
            </crosstab>
于 2013-08-14T07:26:58.890 回答
0

在您的变量声明中,您有“计数”计算:

<variable name="var_2113924770" class="java.lang.Integer" resetType="Group" resetGroup="group_2113924770" calculation="Count">
    <variableExpression><![CDATA[$F{geo.c}]]></variableExpression>
</variable>

你应该有“总和”。如果我正确理解了您的问题,那将为您解决。

于 2013-08-12T20:35:20.287 回答