ho.hince Posted July 16, 2019 Share Posted July 16, 2019 I've created a simple JasperReport example: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> And the subreport, 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> The report use the sample DB, and here are the screen shoot:SubReport, with the parameter country set to "France", it contain the first page as below and 7 other empty pages./sites/default/files/user_uploads/ho.hince/capture.pngMainReport, The first two page as below, a total of 93 pages, most of them which are empty/sites/default/files/user_uploads/ho.hince/capture_0.png/sites/default/files/user_uploads/ho.hince/capture_1.png Link to comment Share on other sites More sharing options...
joseng62 Posted July 16, 2019 Share Posted July 16, 2019 Here we go, much better I believe. StackOverflowExample.jrxml:<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 --><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="40"> <subreport> <reportElement x="0" y="0" width="556" height="40" 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.4.0.final using JasperReports Library version 6.4.1 --><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> <summary> <band height="155"> <lineChart> <chart evaluationTime="Report"> <reportElement x="0" y="0" width="255" height="155" 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> </summary></jasperReport>This will produce 6 pages, 4 charts on each page execpt one on the last page. Link to comment Share on other sites More sharing options...
ho.hince Posted July 17, 2019 Author Share Posted July 17, 2019 Great answer, but I have the soluiton here:https://stackoverflow.com/questions/57057135/jasper-print-when-create-white-space/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now