There are lots of tutorials on how to zebra stripe the rows of a report. Like this:
+-------+-------+
| Value | Color |
+-------+-------+
| A | white |
| A | black |
| B | white |
| B | black |
| B | white |
| C | black |
| D | white |
| D | black |
+-------+-------+
But what I want to do is a grouped stripping. Like this:
+-------+-------+
| Value | Color |
+-------+-------+
| A | white |
| A | white |
| B | black |
| B | black |
| B | black |
| C | white |
| D | black |
| D | black |
+-------+-------+
I'm using the column "Value" as the expression of a group and my data is sorted by "Value". "black" is a black rectangle to be printed when the group is black. "white" is the absence of the black rectangle. I want a variable that I can put in "Print When Expression" of the black rectangle.
What I've tried until now:
Create a variable $V{print}
Initial Value Expression: false
Variable Expression: !$V{print}
Increment type: Group
Increment group: Value
I expected the value of $V{print} to change to it's opposite value every time the group changed. What I get is the normal striped list (black, white, black, white...)
The problem with you current solution is:
calculationType="Nothing"
Nothing: This is the default calculation type that a variable performs. It means that the variable's value is recalculated with every iteration in the data source and that the value returned is obtained by simply evaluating the variable's expression.
This type of calculation will invalidate your incrementType, hence the incrementType has no effect, since we are not calculating. This is why currently you get black,white,black,white.
This will achieve your desired result
Variable definition (lets do some calculation example increment by 1 every time group change, sum or count)
<variable name="GroupCnt" class="java.lang.Integer" incrementType="Group" incrementGroup="myGroup" calculation="Sum">
<variableExpression><![CDATA[1]]></variableExpression>
</variable>
conditionExpression (we can use modulus operator the variable GroupCnt)
<conditionExpression><![CDATA[$V{GroupCnt}%2==0]]></conditionExpression>
Example of complete jrxml (I have added an rectangle as OP comment on this)
<?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="group" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c1d9b4b7-6162-4b17-b871-3cf3b867d1ef">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="myStyle">
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{GroupCnt}.intValue()%2==0)]]></conditionExpression>
<style mode="Opaque" forecolor="#FFFFFF" backcolor="#000000"/>
</conditionalStyle>
</style>
<field name="Value" class="java.lang.String"/>
<variable name="GroupCnt" class="java.lang.Integer" incrementType="Group" incrementGroup="myGroup" calculation="Sum">
<variableExpression><![CDATA[1]]></variableExpression>
</variable>
<group name="myGroup">
<groupExpression><![CDATA[$F{Value}]]></groupExpression>
</group>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement style="myStyle" x="0" y="0" width="150" height="20" uuid="7ca1ac35-6249-4ba6-ac87-031f8d410d2e"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{Value}]]></textFieldExpression>
</textField>
<rectangle>
<reportElement style="myStyle" x="150" y="0" width="150" height="20" uuid="d322e0df-0d39-4370-90e6-58305d449852"/>
</rectangle>
</band>
</detail>
</jasperReport>
new Boolean($V{GroupCnt}.intValue()%2==0), new Boolean and intValue() is just use to be compatibile with old jasper report versions it is not needed in latest versions
Result
Related
I have a report with 2 bands:
A detail band used to display rows that have Group=N i.e. if Group <> N, it is hidden
A group footer, used to display an aggregate of rows that have Group=Y i.e. if Group <> Y, it is hidden
Both bands display a Date, Name, and Amount. The group footer aggregates the Amount field.
I would like to suppress repeating Dates.
E.g, given the following data:
+------------+------+-------+--------+
| Date | Name | Group | Amount |
+------------+------+-------+--------+
| 2020-06-01 | A | Y | 5 |
| 2020-06-01 | A | Y | 10 |
| 2020-06-01 | D | N | 2 |
| 2020-06-01 | Z | Y | 4 |
| 2020-06-02 | B | N | 1 |
| 2020-06-02 | G | Y | 6 |
| 2020-06-02 | G | Y | 3 |
+------------+------+-------+--------+
It should display:
+------------+------+--------+
| Date | Name | Amount |
+------------+------+--------+
| 2020-06-01 | A | 15 |
| | D | 2 |
| | Z | 4 |
| 2020-06-02 | B | 1 |
| | G | 9 |
+------------+------+--------+
With isPrintRepeatedValues="false", it duplicates dates as they are in different bands:
+------------+------+--------+
| Date | Name | Amount |
+------------+------+--------+
| 2020-06-01 | A | 15 |
| 2020-06-01 | D | 2 |
| | Z | 4 |
| 2020-06-02 | B | 1 |
| 2020-06-02 | G | 9 |
+------------+------+--------+
Adding a:
<group name="DateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
and suppressing the Date fields with the expressions:
<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]</printWhenExpression>
doesn't work either, as the following display shows. I've included the Group and DateGroup_Count values for debugging:
+------------+------+--------+-------+-----------------+
| Date | Name | Amount | Group | DateGroup_COUNT |
+------------+------+--------+-------+-----------------+
| | A | 15 | Y | 2 |
| | D | 2 | N | 3 |
| | Z | 4 | Y | 4 |
| 2020-06-02 | B | 1 | N | 1 |
| | G | 9 | Y | 3 |
+------------+------+--------+-------+-----------------+
2020-06-01 should be displayed in the first row, but in the above the DateGroup_COUNT value represents the last row in the aggregated band, so the Date field is suppressed when it shouldn't be.
Note that the above can possibly be achieved in a single band. It represents a simplified version of a report that cannot be achieved using a single band as it:
calculates the Amount column differently in each band
has different fields in each band which would need to be selectively shown/hidden. These would also overlap
The CSV used for the data source:
Date,Name,Group,Amount
2020-06-01,A,Y,5
2020-06-01,A,Y,10
2020-06-01,D,N,2
2020-06-01,Z,Y,4
2020-06-02,B,N,1
2020-06-02,G,Y,6
2020-06-02,G,Y,3
The JRXML
<?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="duplicatetest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasuppressiontestdata"/>
<field name="Date" class="java.util.Date"/>
<field name="Name" class="java.lang.String"/>
<field name="Group" class="java.lang.String"/>
<field name="Amount" class="java.math.BigDecimal"/>
<variable name="groupTotal" class="java.math.BigDecimal" resetType="Group" resetGroup="Aggregate" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<group name="DateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
<group name="Aggregate">
<groupExpression><![CDATA[$F{Group}]]></groupExpression>
<groupFooter>
<band height="30">
<printWhenExpression><![CDATA[EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField evaluationTime="Group" evaluationGroup="DateGroup" pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup">
<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textElement>
<paragraph lineSpacing="Fixed"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{groupTotal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="130" height="30"/>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement x="134" y="0" width="116" height="30"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[DateGroup_COUNT]]></text>
</staticText>
<staticText>
<reportElement x="390" y="0" width="68" height="30"/>
<text><![CDATA[Group]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[!EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField evaluationTime="Group" evaluationGroup="DateGroup" pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup">
<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I created new variable to read DateGroup count . On change of each date reset to 1.
And printed Date only when Dategroup is 1.
Check below jrxml. It gives your desired output.
<?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="duplicatetest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="04479c0d-d012-45d8-a8d1-f281276aba62">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasuppressiontestdata"/>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="Date" class="java.util.Date"/>
<field name="Name" class="java.lang.String"/>
<field name="Group" class="java.lang.String"/>
<field name="Amount" class="java.math.BigDecimal"/>
<variable name="groupTotal" class="java.math.BigDecimal" resetType="Group" resetGroup="Aggregate" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<variable name="COUNT_GROUP_1" class="java.lang.Integer" resetType="Group" resetGroup="DateGroup" incrementType="Group" incrementGroup="DateGroup">
<variableExpression><![CDATA[( $V{Aggregate_COUNT} == 1) ? $V{COUNT_GROUP_1} + 1 : $V{COUNT_GROUP_1}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="DateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
<group name="Aggregate">
<groupExpression><![CDATA[$F{Group}]]></groupExpression>
<groupFooter>
<band height="30">
<printWhenExpression><![CDATA[EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup" uuid="16819840-1496-42ac-aec8-02e50a104608">
<printWhenExpression><![CDATA[$V{COUNT_GROUP_1}==1]]></printWhenExpression>
</reportElement>
<textElement>
<paragraph lineSpacing="Fixed"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30" uuid="5008a25a-6654-4ffc-95dd-cdefac6b1c3a"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30" uuid="c89330be-7a7b-4721-b881-10e5df8ced68"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{groupTotal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30" uuid="5dd2909c-4ffb-4296-9a42-3656bed378fe"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30" uuid="61b8eb92-90ec-4727-a69c-642f063f08fe"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="130" height="30" uuid="f05195da-f90c-4026-9e38-89a902853871"/>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement x="134" y="0" width="116" height="30" uuid="2d40f4cc-a795-4e67-9fac-7a6e77085de3"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="260" y="0" width="100" height="30" uuid="e5c44c50-93da-45a0-8a21-18fab3295972"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement x="458" y="0" width="100" height="30" uuid="1b22596b-22e0-4b22-b2ab-9ed699ddd61f"/>
<textElement textAlignment="Right"/>
<text><![CDATA[DateGroup_COUNT]]></text>
</staticText>
<staticText>
<reportElement x="390" y="0" width="68" height="30" uuid="8210e103-4473-4a5e-a915-a568356f76ac"/>
<text><![CDATA[Group]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[!EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup" uuid="9112a549-c2e1-4b49-996e-d12f5f1307cf">
<printWhenExpression><![CDATA[$V{COUNT_GROUP_1}==1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30" uuid="111ee635-3426-4a2b-8f68-3e4e6dc003c3"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30" uuid="c0eac89a-54ac-4480-9fa1-3c841aed7d89"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30" uuid="b2ff7aaf-ab81-4b3d-a45f-9094044af7bf"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30" uuid="5ac47f28-41e3-4940-bcdb-91b2ba85f30b"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
If I understand the task right, all you need is to create two groups and show total for 2nd group.
You can solve this task in 5 steps:
Sort data by Date and Name fields.
Create group by Date field
Create group by Name field
Create variable to show sum of all Amount values at each group by Name
Create simple report using Detail and Column Header bands only.
The report's template
The template is using data adapter based on your csv file.
The jrxml code:
<?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="duplicatetest" pageWidth="390" pageHeight="842" columnWidth="350" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasuppressiontestdata"/>
<field name="Date" class="java.util.Date"/>
<field name="Name" class="java.lang.String"/>
<field name="Group" class="java.lang.String"/>
<field name="Amount" class="java.math.BigDecimal"/>
<sortField name="Date"/>
<sortField name="Name"/>
<variable name="groupTotal" class="java.math.BigDecimal" resetType="Group" resetGroup="nameGroup" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<group name="dateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
<group name="nameGroup">
<groupExpression><![CDATA[$F{Name}]]></groupExpression>
</group>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="130" height="30"/>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement x="130" y="0" width="120" height="30"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="250" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Amount]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField pattern="yyyy-MM-dd">
<reportElement x="0" y="0" width="130" height="30">
<printWhenExpression><![CDATA[$V{dateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="130" y="0" width="120" height="30">
<printWhenExpression><![CDATA[$V{nameGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField evaluationTime="Auto">
<reportElement x="250" y="0" width="100" height="30">
<printWhenExpression><![CDATA[$V{nameGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$V{groupTotal}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I used printWhenExpression property for showing data of only first record for each Date and Name groups. I removed all "duplicates" with help of this trick.
With help of isRemoveLineWhenBlank="true" property I hid all blank lines (for cases $V{nameGroup_COUNT} > 1).
The last trick is to set evaluationTime="Auto" property for textField with total sum.
Output result
The generated report looks like this at JSS:
I want add set text in textField and staticText as it will divide in equal space in jasper report.
Text should be distributed like below image.
Setting textAlignment to "Justified", but it didn't work.
Can someone suggest me the solution for this?
I have to do it in jasper report and generate an report in PDF file.
<staticText>
<reportElement x="52" y="34" width="135" height="20" uuid="44eed122-c07e-42d0-b696-a6ad54b759a4"/>
<textElement textAlignment="Justified" verticalAlignment="Middle" rotation="None">
<font fontName="Serif" size="12"/>
</textElement>
<text><![CDATA[Welcome]]></text>
</staticText>
Text should be distributed like bellow text in PDF report.
Justification - the spaces between words and between glyphs or letters are stretched or compressed in order to align both the left and right ends of consecutive lines of text. When using justification, it is customary to treat the last line of a paragraph separately by simply left or right aligning it, depending on the language direction.
So you need lines of text to see the difference between textAlignment="Left" and textAlignment="Justified" values. I guess the alignment textAlignment="Justified" works properly but it treats the text as "the last line of a paragraph". If you put long text in staticText you will have no troubles (v6.9.0.). See the image below.
The workaround could be something just like this:
Create tabSet variable
<variable name="tabSet" class="java.lang.String">
<variableExpression><![CDATA[" "]]></variableExpression>
<initialValueExpression><![CDATA[" "]]></initialValueExpression></variableExpression>
</variable>
Add the variable to any expression you need to be justified including the last\first line
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>
Set alignment and markup
<textElement textAlignment="Justified" markup="html"/>
The full example below:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3 -->
<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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="00216f45-7b94-4847-94ea-7ea4f1508a6e">
<scriptlet name="DynTable" class="net.sf.jasperreports.engine.JRDefaultScriptlet">
<scriptletDescription><![CDATA[]]></scriptletDescription>
</scriptlet>
<variable name="tabSet" class="java.lang.String">
<variableExpression><![CDATA[" "]]></variableExpression>
<initialValueExpression><![CDATA[" "]]></initialValueExpression>
</variable>
<detail>
<band height="560" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="20" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Justified" verticalAlignment="Middle" markup="styled"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="550" height="20" uuid="1132e9a7-8b30-4167-94ce-a013480dca9d"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Left"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Left" verticalAlignment="Justified"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="80" width="550" height="20" uuid="bc341f2a-916e-4391-90dc-8b68684d2c6c"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="100" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Justified" verticalAlignment="Justified" markup="none"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="160" width="550" height="20" uuid="8472fd7d-b77c-46bf-9a11-b5f4cd1fff78"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Left"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="180" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Left" verticalAlignment="Top"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="240" width="550" height="20" uuid="8da01066-6dc6-4551-8530-2ac179fab340"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Workaround"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="260" width="550" height="20" uuid="931c0377-e69d-41e9-8c0e-eec6b53d14d1"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="280" width="550" height="20" uuid="aa466b7b-c67b-4cf7-bb52-09d52fceedf6"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="300" width="550" height="20" uuid="e6cb9bd0-80b6-4138-9e58-803caf5b9c54"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="1" y="320" width="550" height="20" uuid="113a944e-b09b-419e-abf9-06b76959731d"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="340" width="550" height="20" uuid="920883bb-cd3a-4a26-99e4-ad0a5415033f"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I'm using iReport 5.6.0 and i want to create new page for each group.
For example i have table people_i_know:
Id| Name | State
1 | Tom | friends
2 | Jim | friends
3 | Mike | enemy
4 | Alex | friends
5 | Julie| enemy
My SQL should be like this:
SELECT Id,Name,State FROM people_i_know GROUP BY State;
And in this example iReport should give me two pages with detail band like this:
This should be on page 1.
1 | Tom | friends
2 | Jim | friends
4 | Alex | friends
And this should be on page 2.
3 | Mike | enemy
5 | Julie| enemy
How do i make that iReport make something like this?
You do not need to group in query, just order them
SELECT Id,Name,State FROM people_i_know State ORDER BY State;
in jrxml
you will have a field relative to the State column
<field name="State" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
create a group on State with attribute isStartNewPage="true"
<group name="State" isStartNewPage="true">
<groupExpression><![CDATA[$F{State}]]></groupExpression>
</group>
and now just put the fields you like to display in the detail band
In MySQL workbench I get 3 rows:
mysql> select * from person;
+-----+------+
| ID | NAME |
+-----+------+
| A01 | A01 |
| A02 | A02 |
| A03 | A03 |
+-----+------+
3 rows in set (0.00 sec)
but when I use jrxml and show to pdf
I just can get a one row
+-----+------+
| ID | NAME |
+-----+------+
| A01 | A01 |
+-----+------+
and this's my jrxml
<?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="T0113" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" >
<queryString>
<![CDATA[select * from person ]]>
</queryString>
<field name="ID" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="NAME" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<group name="ID">
<groupExpression><![CDATA[$F{ID}]]></groupExpression>
</group>
<group name="NAME">
<groupExpression><![CDATA[$F{NAME}]]></groupExpression>
</group>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="240" y="0" width="100" height="30" />
<text><![CDATA[PDFPDF]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band height="61" splitType="Stretch">
<textField>
<reportElement x="170" y="15" width="100" height="30" />
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="320" y="10" width="100" height="30" />
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
</jasperReport>
So how to fix the problem ?
This is because you field's are in the wrong band.
Column Header This section appears at the beginning of each column in
the generated document.
Detail This section is repeated for each line of data supplied by the
report's data source. The detail section can be made of multiple
bands.
Currently you have them in the columnHeader you need to but them in the detail band
<detail>
<band height="61" splitType="Stretch">
<textField>
<reportElement x="170" y="15" width="100" height="30" />
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="320" y="10" width="100" height="30" />
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
</band>
</detail>
To learn more about different report sections see Tutorial report section and JRBand API
just change <![CDATA[$F{ID}]]> and <![CDATA[$F{NAME}]]> in the detail band NOT in columnHeader
I'm working with Jaspersoft Studio 5.6, trying to create a report that shows multiple XY (or bar) charts based upon a grouping parameter. I've dumbed down my original data to the following, and I still can't figure it out.
DATA
+------+------+-------+
| xrow | yrow | group |
+------+------+-------+
| 1 | 11 | 1 |
| 2 | 12 | 1 |
| 3 | 10 | 1 |
| 1 | 5 | 2 |
| 2 | 10 | 2 |
| 3 | 14 | 2 |
+------+------+-------+
Here is my XML code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="group3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="cdd6d2cf-7c0c-4d79-8cfe-a4f1e04da233">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Office"/>
<queryString language="SQL">
<![CDATA[SELECT maintenance.test.xrow,
maintenance.test.yrow,
maintenance.test.group
FROM maintenance.test]]>
</queryString>
<field name="xrow" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="yrow" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="group" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<sortField name="group"/>
<sortField name="xrow"/>
<group name="Group1">
<groupExpression><![CDATA[$F{group}]]></groupExpression>
<groupHeader>
<band height="190">
<barChart>
<chart evaluationTime="Report">
<reportElement x="40" y="0" width="460" height="190" uuid="582be7ed-4b48-4d55-a2b6-1295290d34e3"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset resetType="Group" resetGroup="Group1"/>
<categorySeries>
<seriesExpression><![CDATA["SERIES 1"]]></seriesExpression>
<categoryExpression><![CDATA[$F{xrow}]]></categoryExpression>
<valueExpression><![CDATA[$F{yrow}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot/>
<itemLabel/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</barPlot>
</barChart>
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
</jasperReport>
I've created a report group for the column "group"
I'm putting the chart in the Group header band. and I've tried setting "reset on" to GROUP, as well as REPORT (in chart wizard) with no change in results. See below screen shot.
I'm at a loss of what to try next.
I took a closer look at the chart properties, and noticed there was a parameter called Evaluation Time, Changed it from "Report" to the name of the group. Alternatively change the following..
<chart evaluationTime="Report">
to
<chart evaluationTime="Group" evaluationGroup="group">
With the chart in the group header\footer, this will allow the chart to only show the current group data.