Jasper Report 预览中元素的奇怪定位

Weird positioning of elements inside a Jasper Report preview

我正在使用 TIBCO Jaspersoft® Studio 6.8.0,但我在定位时遇到了一些问题。我认为定位会有点自动跟随 GUI,但显然它不是那样工作的。

我有一个子报表(现在不需要主报表)调用其他 2 个子报表,一个用于饼图,一个用于交叉表。他们都使用来自外部 json(本地 json)的子数据集工作得很好。
问题是我无法正确定位它们:我需要将饼图定位在页面的顶部,交叉表紧靠下方。

这是子报表(现在用作主报表)。你可以看到我正在使用模拟(xml 调用 json),我将在问题末尾添加 json。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b  -->
<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="ReportAnomalies_subReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0a8e5b1c-8d35-4290-a283-c7fb4e197131">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="report\mock\TestTemp.xml"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
    <style name="DefaultTableStyle" style="DefaultStyle">
        <box>
            <pen lineWidth="0.5" lineColor="#888888"/>
        </box>
    </style>
    <style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
    <style name="Table_H" style="DefaultTableHeaderStyle"/>
    <style name="Table_T" style="DefaultTableStyle"/>
    <style name="Table_D" style="DefaultTableStyle"/>
    <field name="NomeAnomalia" class="java.lang.String"/>
    <field name="GruppiAnomalie" class="java.lang.Integer"/>
    <field name="Total" class="java.lang.String"/>
    <detail>
        <band height="290">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <subreport>
                <reportElement key="" x="10" y="0" width="535" height="290" uuid="37faa740-d0e0-457e-bb66-a9dbfc252683"/>
                <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("pieChartData")]]></dataSourceExpression>
                <subreportExpression><![CDATA["ReportAnomalies_pieChart.jasper"]]></subreportExpression>
            </subreport>
        </band>
        <band height="80">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <subreport>
                <reportElement key="" style="DefaultTableStyle" x="10" y="0" width="535" height="80" uuid="ca3470c0-044b-4905-9524-5c0a948961a5">
                    <property name="com.jaspersoft.studio.unit.x" value="px"/>
                    <property name="com.jaspersoft.studio.unit.y" value="px"/>
                </reportElement>
                <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("anomalyList")]]></dataSourceExpression>
                <subreportExpression><![CDATA["ReportAnomalies_crosstab.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>

饼图子报表(我使用解决方法<printWhenExpression><![CDATA[$F{print} == 1]]></printWhenExpression>,因为如果不使用它会打印饼图 3 次)

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b  -->
<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="ReportAnomalies_pieChart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0a8e5b1c-8d35-4290-a283-c7fb4e197131">
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
    <style name="DefaultTableStyle" style="DefaultStyle">
        <box>
            <pen lineWidth="0.5" lineColor="#888888"/>
        </box>
    </style>
    <style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
    <style name="Table_H" style="DefaultTableHeaderStyle"/>
    <style name="Table_T" style="DefaultTableStyle"/>
    <style name="Table_D" style="DefaultTableStyle"/>
    <field name="print" class="java.lang.Integer"/>
    <field name="severityName" class="java.lang.String"/>
    <field name="severityValue" class="java.lang.Integer"/>
    <field name="severityLabel" class="java.lang.String"/>
    <detail>
        <band height="285" splitType="Stretch">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <pieChart>
                <chart evaluationTime="Report">
                    <reportElement style="DefaultTableStyle" x="40" y="0" width="420" height="280" uuid="65c16b4b-d856-4d7f-bb7b-a0c0aa0f3a3a">
                        <property name="com.jaspersoft.studio.unit.height" value="px"/>
                        <printWhenExpression><![CDATA[$F{print} == 1]]></printWhenExpression>
                    </reportElement>
                    <box>
                        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <pieDataset maxCount="3">
                    <keyExpression><![CDATA[$F{severityName}]]></keyExpression>
                    <valueExpression><![CDATA[$F{severityValue}]]></valueExpression>
                    <labelExpression><![CDATA[$F{severityLabel}]]></labelExpression>
                </pieDataset>
                <piePlot>
                    <plot>
                        <seriesColor seriesOrder="0" color="#80E31E"/>
                        <seriesColor seriesOrder="1" color="#F09918"/>
                        <seriesColor seriesOrder="2" color="#DE3700"/>
                    </plot>
                    <itemLabel/>
                </piePlot>
            </pieChart>
        </band>
    </detail>
</jasperReport>

现在交叉表子报表

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b  -->
<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="Prova" pageWidth="595" pageHeight="842" orientation="Landscape" whenNoDataType="NoPages" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" isSummaryWithPageHeaderAndFooter="true" uuid="1916d28f-c2ed-4735-a541-6dfbd82fe676">
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
    <style name="DefaultTableStyle" style="DefaultStyle">
        <box>
            <pen lineWidth="0.5" lineColor="#888888"/>
        </box>
    </style>
    <style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
    <style name="Table_H" style="DefaultTableHeaderStyle"/>
    <style name="Table_T" style="DefaultTableStyle"/>
    <style name="Table_D" style="DefaultTableStyle"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="NomeAnomalia" class="java.lang.String"/>
    <field name="Value" class="java.lang.String"/>
    <field name="Code" class="java.lang.String"/>
    <field name="Severity" class="java.lang.String"/>
    <field name="GruppiAnomalie" class="java.lang.String"/>
    <variable name="VI" class="java.lang.Float">
        <variableExpression><![CDATA[Float.parseFloat($F{Value})]]></variableExpression>
    </variable>
    <variable name="GruppiAnomalieI" class="java.lang.Integer">
        <variableExpression><![CDATA[Integer.parseInt($F{GruppiAnomalie})]]></variableExpression>
    </variable>
    <group name="Group1">
        <groupExpression><![CDATA[$V{GruppiAnomalieI}]]></groupExpression>
        <groupFooter>
            <band height="80">
                <crosstab columnBreakOffset="20">
                    <reportElement x="30" y="0" width="520" height="70" uuid="af9d4537-350c-4e0b-a338-009d92c884d5">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                        <property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
                    </reportElement>
                    <box leftPadding="3"/>
                    <crosstabDataset>
                        <dataset resetType="Group" resetGroup="Group1"/>
                    </crosstabDataset>
                    <rowGroup name="Severity1" width="30">
                        <bucket class="java.lang.String">
                            <bucketExpression><![CDATA[$F{Severity}]]></bucketExpression>
                        </bucket>
                        <crosstabRowHeader>
                            <cellContents mode="Opaque" style="Table_H">
                                <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                <textField>
                                    <reportElement x="0" y="0" width="30" height="20" uuid="683211f0-a5a5-4cb4-aadc-658e5185baca">
                                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                    </reportElement>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="8"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$V{Severity1}.substring(4)]]></textFieldExpression>
                                </textField>
                            </cellContents>
                        </crosstabRowHeader>
                        <crosstabTotalRowHeader>
                            <cellContents mode="Opaque" style="Table_T">
                                <staticText>
                                    <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="b709de74-24d7-42d1-975c-3ff583a2f091"/>
                                    <text><![CDATA[Totale Severity1]]></text>
                                </staticText>
                            </cellContents>
                        </crosstabTotalRowHeader>
                    </rowGroup>
                    <columnGroup name="Code1" height="20">
                        <bucket class="java.lang.String">
                            <bucketExpression><![CDATA[$F{Code}]]></bucketExpression>
                        </bucket>
                        <crosstabColumnHeader>
                            <cellContents mode="Opaque" style="Table_H">
                                <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                <textField>
                                    <reportElement x="0" y="0" width="25" height="20" uuid="8e897853-1771-4c8e-af55-24e5d5e3708a"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="7"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$V{Code1}]]></textFieldExpression>
                                </textField>
                            </cellContents>
                        </crosstabColumnHeader>
                        <crosstabTotalColumnHeader>
                            <cellContents mode="Opaque" style="Table_T">
                                <staticText>
                                    <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="0423ca98-83a4-48b4-828b-ecc91f72c6df"/>
                                    <text><![CDATA[Totale Code1]]></text>
                                </staticText>
                            </cellContents>
                        </crosstabTotalColumnHeader>
                    </columnGroup>
                    <measure name="Value_MEASURE1" class="java.lang.Float" calculation="Sum">
                        <measureExpression><![CDATA[$V{VI}]]></measureExpression>
                    </measure>
                    <measure name="NA" class="java.lang.String">
                        <measureExpression><![CDATA["n/a"]]></measureExpression>
                    </measure>
                    <crosstabCell width="25" height="20">
                        <cellContents mode="Opaque" style="Table_D">
                            <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                            <textField pattern="#,##0.##">
                                <reportElement x="0" y="0" width="25" height="20" uuid="8f7c6a83-bec1-4fdd-995b-c15df0712202"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="7"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$V{Value_MEASURE1} == -1 ? $V{NA} : $V{Value_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                </crosstab>
            </band>
        </groupFooter>
    </group>
</jasperReport>

最后是 json 文件,非常简单

[   
    {
        "NomeAnomalia": "MIT Impalcati,Travi,Traversi CA CAP",
        "GruppiAnomalie": 201,
        "Total": "6%",
        "anomalyList": [
            {
                "GruppiAnomalie": 201,
                "Code": "cacap1",
                "Name": "Macchie di umidita passiva",
                "Severity": "0 - Lieve",
                "Value": 3.2736806021763885
            },
            {
                "GruppiAnomalie": 201,
                "Code": "cacap12",
                "Name": "Macchie di umidita passiva",
                "Severity": "0 - Lieve",
                "Value": 1.2736806021763885
            },
            {
                "GruppiAnomalie": 201,
                "Code": "cacap16",
                "Name": "Macchie di umidita passiva",
                "Severity": "2 - Forte",
                "Value": 0.7736806021763885
            },
            {
                "GruppiAnomalie": 201,
                "Code": "DifGen1",
                "Name": "Macchie di umidita passiva",
                "Severity": "1 - Media",
                "Value": 1.571812154
            }
        ],
        "pieChartData": [
            {"print": 1, "severityName": "Lieve", "severityValue": 25, "severityLabel": "25%"},
            {"print": 0, "severityName": "Media", "severityValue": 15, "severityLabel": "15%"},
            {"print": 0, "severityName": "Forte", "severityValue": 38, "severityLabel": "38%"}
        ]
    },
    {
        "NomeAnomalia": "MIT Pile,Spalle,Fondazioni CLS",
        "GruppiAnomalie": 202,
        "Total": "6%",
        "anomalyList": [
            {
                "GruppiAnomalie": 202,
                "Code": "cacap1",
                "Name": "Macchie di umidita passiva",
                "Severity": "0 - Lieve",
                "Value": 3.2736806021763885
            },
            {
                "GruppiAnomalie": 202,
                "Code": "cacap12",
                "Name": "Macchie di umidita passiva",
                "Severity": "0 - Lieve",
                "Value": 1.2736806021763885
            },
            {
                "GruppiAnomalie": 202,
                "Code": "cacap16",
                "Name": "Macchie di umidita passiva",
                "Severity": "2 - Forte",
                "Value": 0.7736806021763885
            }
        ],
        "pieChartData": [
            {"print": 1, "severityName": "Lieve", "severityValue": 25, "severityLabel": "5%"},
            {"print": 0, "severityName": "Media", "severityValue": 15, "severityLabel": "87%"},
            {"print": 0, "severityName": "Forte", "severityValue": 38, "severityLabel": "47%"}
        ]
    }
]

我认为问题不会出现在子报表中...至少不会出现在操作部分,但我仍然不知道为什么会这样显示(3 页而不是 2 页和奇怪的定位)...它们是按顺序排列的,第一页、第二页和第三页

有什么建议吗?

您在饼图子报表中使用的解决方法导致生成的报表中出现空白 space。

您为饼图元素设置了 print when 表达式。这使得饼图不会为第二条和第三条记录打印,但即使图表不打印,详细信息带本身仍会占用其声明的高度。

解决此问题的一个简单方法是为带而不是图表元素设置 print when 表达式。这将使整个乐队不打印第二和第三张唱片。

但更正常的解决方案是将图表元素放在摘要带中(表达式时不打印),并完全删除详细信息带。