问题描述
我使用示例数据库创建了一个简单的JasperReport示例:
StackOverflowExample.jrxml:
I've created a simple JasperReport example, using the sample DB:
StackOverflowExample.jrxml:
<?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="StackOverflowExample" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<queryString>
<![CDATA[SELECT DISTINCT "ORDERS"."SHIPCOUNTRY"
FROM "ORDERS"]]>
</queryString>
<field name="SHIPCOUNTRY" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="SHIPCOUNTRY"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="183">
<subreport>
<reportElement x="0" y="0" width="556" height="170" isRemoveLineWhenBlank="true" uuid="4b89b974-f838-4bb7-85b6-1b0f1079c1e6"/>
<subreportParameter name="country">
<subreportParameterExpression><![CDATA[$F{SHIPCOUNTRY}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["StackOverflowExampleSubReport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
StackOverflowExampleSubReport.jrxml:
<?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="StackOverflowExample" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<parameter name="country" class="java.lang.String">
<defaultValueExpression><![CDATA["France"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT "ORDERS"."ORDERDATE",
"ORDERS"."FREIGHT"
FROM "ORDERS"
WHERE "ORDERS"."SHIPCOUNTRY" = $P{country}]]>
</queryString>
<field name="ORDERDATE" class="java.sql.Timestamp">
<property name="com.jaspersoft.studio.field.label" value="ORDERDATE"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
</field>
<field name="FREIGHT" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="FREIGHT"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="160">
<lineChart>
<chart evaluationTime="Report">
<reportElement x="15" y="5" width="255" height="155" isRemoveLineWhenBlank="true" uuid="3b5f7d89-490b-468f-9112-f606f4eda437">
<printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
</reportElement>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA[$P{country}]]></seriesExpression>
<categoryExpression><![CDATA[$F{ORDERDATE}]]></categoryExpression>
<valueExpression><![CDATA[$F{FREIGHT}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
</linePlot>
</lineChart>
</band>
</detail>
</jasperReport>
问题是我有很多空的无用空间
子报表
子报表的图像,参数country
设置为"France"
,包含下面的第一页和其他7个空白页
https://community.jaspersoft.com/sites/默认/文件/user_uploads/ho.hince/capture.png
MainReport
对于主报告,如下所示的前两页,共有93页,其中大多数是空白的:
https://community.jaspersoft.com/sites/默认/文件/user_uploads/ho.hince/capture_0.png
https://community.jaspersoft.com/sites/默认/文件/user_uploads/ho.hince/capture_1.png
The problem is that I have a lot of empty useless space
Subreport
An image of the subreport, with the parameter country
set to "France"
, it contains the first page as below and 7 other empty pages
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture.png
MainReport
For the main report, the first two page as below, there is a total of 93 pages, most of them which are empty:
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture_0.png
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture_1.png
留白的原因是我在子报表中只打印了一次图表.我使用属性printWhen
来实现.printWhen => new Boolean($V{REPORT_COUNT}.intValue()==1)
The reason for the white space is that I print the chart in the subreport report once. I do it with the property printWhen
.printWhen => new Boolean($V{REPORT_COUNT}.intValue()==1)
我无法将图表移出详细信息"区域,因为我已经用Column Count = 2
和Print Order = Horizontal
设置了子报表属性.我这样做是因为我希望将图表分成两列: https://community.jaspersoft.com/sites/默认/文件/user_uploads/ho.hince/capture_2.png
(这里的问题是图表是重复的)
I can't move the chart out of the Detail band, because I've set the subreport properties with Column Count = 2
and Print Order = Horizontal
. I did that, cause I wish to have the charts in two column just like that:
https://community.jaspersoft.com/sites/default/files/user_uploads/ho.hince/capture_2.png
(The problem here is that the chart are duplicated)
推荐答案
我找到了解决方案,我只打印一次图表,但是每次都打印明细区域,所以我不得不移动print when
表达式进入详细信息"乐队.
I found the solution, I was printing the chart only once, but I was printing the Detail band each time, so I had to move the print when
expression to the Detail band.
<band height="160">
<printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
主图表必须具有垂直顺序的两列,以及子报表2的水平顺序.
The main chart must have two column in vertical order, and the subreport 2 column in horizontal order.
您还可以更改主要报表属性:
Print Order
==> vertical
和Column Count
==> 2
You can also change the main report properties :Print Order
==> vertical
and Column Count
==> 2
StackOverflowExample.jrxml:
<?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="StackOverflowExample" columnCount="2" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<queryString>
<![CDATA[SELECT "ORDERS"."SHIPCOUNTRY",
Max("ORDERS"."SHIPCOUNTRY")
FROM "ORDERS"
GROUP BY "ORDERS"."SHIPCOUNTRY"
ORDER BY "ORDERS"."SHIPCOUNTRY" ASC]]>
</queryString>
<field name="SHIPCOUNTRY" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="SHIPCOUNTRY"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
</field>
<field name="C2" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="C2"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="170">
<subreport>
<reportElement x="-20" y="50" width="297" height="120" isRemoveLineWhenBlank="true" uuid="4b89b974-f838-4bb7-85b6-1b0f1079c1e6">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<subreportParameter name="country">
<subreportParameterExpression><![CDATA[$F{SHIPCOUNTRY}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["StackOverflowExampleSubReport.jasper"]]></subreportExpression>
</subreport>
<textField>
<reportElement x="43" y="0" width="185" height="50" uuid="0c170024-70ea-492f-95fe-99ff3a27cb6d"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="19"/>
</textElement>
<textFieldExpression><![CDATA[$F{SHIPCOUNTRY}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
StackOverflowExampleSubReport.jrxml:
<?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="StackOverflowExample" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="749cd048-9a0d-4a00-89bf-1a75a4565943">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<parameter name="country" class="java.lang.String">
<defaultValueExpression><![CDATA["France"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT "ORDERS"."ORDERDATE",
"ORDERS"."FREIGHT"
FROM "ORDERS"
WHERE "ORDERS"."SHIPCOUNTRY" = $P{country}]]>
</queryString>
<field name="ORDERDATE" class="java.sql.Timestamp">
<property name="com.jaspersoft.studio.field.label" value="ORDERDATE"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
</field>
<field name="FREIGHT" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="FREIGHT"/>
<property name="com.jaspersoft.studio.field.tree.path" value="ORDERS"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="130">
<printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
<lineChart>
<chart evaluationTime="Report">
<reportElement isPrintRepeatedValues="false" x="0" y="3" width="235" height="125" isRemoveLineWhenBlank="true" uuid="3b5f7d89-490b-468f-9112-f606f4eda437"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA[$P{country}]]></seriesExpression>
<categoryExpression><![CDATA[$F{ORDERDATE}]]></categoryExpression>
<valueExpression><![CDATA[$F{FREIGHT}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
</linePlot>
</lineChart>
</band>
</detail>
</jasperReport>
这篇关于贾斯珀(Jasper),“打印时"创建空白,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!