比较jasper报告中的List <date>和颜色填充背景</date>

时间:2013-12-12 09:55:16

标签: jasper-reports

我是 JasperReports 的新手。我的POJO类中有两个List<Date>类型变量。一个是 startDate ,另一个是 endDate 。我是使用 iReport 设计的报告。

现在我想根据当前年份和过去一年填充背景颜色。请帮助任何人

//jrxml file
<?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="sediReport" language="groovy" pageWidth="700" pageHeight="1000" columnWidth="660" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="329333dc-1de2-443a-8874-0b3450e37adf">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="dataset1" uuid="e0f4c24b-03b4-43b3-98f2-0b5a12612149">
    <field name="males" class="java.lang.Integer">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<subDataset name="dataset2" uuid="6de41581-3e22-4d61-ad11-8e37c63a11a4">
    <field name="females" class="java.lang.Integer">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<subDataset name="dataset3" uuid="b52874e4-eb17-4dae-ac85-d2897705958e">
    <field name="trades" class="java.lang.String">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<subDataset name="dataset4" uuid="b4eb6d41-c6a0-4809-b0e0-401205e786c7">
    <field name="totals" class="java.lang.Integer">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<subDataset name="dataset5" uuid="4b76c576-2adb-4019-af00-f4bec587a50d">
    <field name="startDates" class="java.util.Date">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<subDataset name="dataset6" uuid="f30e8749-30dc-463a-8fd7-4c0d5b966588">
    <field name="endDates" class="java.util.Date">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<field name="location" class="java.lang.String"/>
<field name="male" class="java.util.Collection"/>
<field name="female" class="java.util.Collection"/>
<field name="trade" class="java.util.Collection"/>
<field name="total" class="java.util.Collection"/>
<field name="startDate" class="java.util.Collection"/>
<field name="endDate" class="java.util.Collection"/>
<field name="totalMale" class="java.lang.Integer"/>
<field name="totalFemale" class="java.lang.Integer"/>
<field name="totalSize" class="java.lang.Integer"/>
<field name="yearOfEstablishment" class="java.lang.String"/>
<variable name="grandTotal" class="java.lang.Integer" calculation="Sum">
    <variableExpression><![CDATA[$F{totalSize}]]></variableExpression>
</variable>
<variable name="grandTotalMale" class="java.lang.Integer" calculation="Sum">
    <variableExpression><![CDATA[$F{totalMale}]]></variableExpression>
</variable>
<variable name="grandTotalFemale" class="java.lang.Integer" calculation="Sum">
    <variableExpression><![CDATA[$F{totalFemale}]]></variableExpression>
</variable>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="79" splitType="Stretch">
        <staticText>
            <reportElement uuid="0f90ffd2-285b-48c3-93ec-566cc6b36840" x="195" y="0" width="344" height="68"/>
            <textElement>
                <font size="12" isStrikeThrough="false"/>
                <paragraph leftIndent="12"/>
            </textElement>
            <text><![CDATA[                                   Ambuja Cement Foundation
               Skill & Entrepreneurship Development Institute
                                Integrated MPR for All SEDI]]></text>
        </staticText>
    </band>
</title>
<pageHeader>
    <band height="28" splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="59" splitType="Stretch">
        <staticText>
            <reportElement uuid="048621e7-f89e-4376-9669-af4dce17b2be" x="49" y="0" width="100" height="27"/>
            <textElement/>
            <text><![CDATA[location]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="2e7175ee-0c2d-48c3-a014-74867e43840a" x="367" y="27" width="43" height="31"/>
            <textElement/>
            <text><![CDATA[male]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="55fd984e-191f-4e12-9b31-9bdd0dde26a3" x="219" y="0" width="100" height="27"/>
            <textElement/>
            <text><![CDATA[trade]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="f5477b3c-c38b-42c4-994a-162cd927a369" x="318" y="27" width="48" height="31"/>
            <textElement/>
            <text><![CDATA[total]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="45005ec4-18f5-42f8-afb8-ac66c9f3d6b4" x="0" y="0" width="49" height="27"/>
            <textElement>
                <font size="12"/>
            </textElement>
            <text><![CDATA[SN]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="2e7e6c11-dd27-4bcf-a108-b40863b3bc3c" x="149" y="0" width="70" height="27"/>
            <textElement>
                <font size="12"/>
            </textElement>
            <text><![CDATA[SN]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="1def1a2a-0d1b-48cf-9cc7-dd406a86d6c2" x="319" y="0" width="141" height="27"/>
            <textElement>
                <font size="12"/>
            </textElement>
            <text><![CDATA[No Of Trainees]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="594a1745-0a29-4b7f-bd00-e373af935479" x="460" y="2" width="200" height="24"/>
            <textElement>
                <font size="12"/>
            </textElement>
            <text><![CDATA[Course Duration (Month Specific)]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="17ace47d-f685-4b91-85df-7b978b8c17c5" x="410" y="27" width="50" height="31"/>
            <textElement/>
            <text><![CDATA[female]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="1881bfac-8150-4d93-9f05-29b2f957aba2" x="460" y="26" width="92" height="32"/>
            <textElement/>
            <text><![CDATA[startDate]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="ac71639c-449a-4cfe-8516-742e5741b3d1" x="552" y="26" width="108" height="32"/>
            <textElement/>
            <text><![CDATA[endDate]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="220" splitType="Stretch">
        <textField>
            <reportElement uuid="f880ffba-d7db-4a35-8a4d-9f86931b444d" mode="Opaque" x="49" y="0" width="100" height="20" backcolor="#99CCFF"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{location}]]></textFieldExpression>
        </textField>
        <componentElement>
            <reportElement uuid="17e26b3b-76e6-4337-b74a-ab09216a1cda" x="219" y="0" width="99" height="20"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset3" uuid="4a7a9ea4-7faa-4c28-89a8-e7ed25ac283d">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{trade})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="99">
                    <textField>
                        <reportElement uuid="bc871ddd-1b77-42d8-ab4a-b5f8c9f7966e" mode="Opaque" x="0" y="0" width="99" height="20" backcolor="#CCCCFF"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{trades}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
        <componentElement>
            <reportElement uuid="7d11b527-1024-44e0-a632-12cd885f0016" x="318" y="0" width="48" height="20"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset4" uuid="c845414e-2a23-43a5-bce5-cb2940ac8c9c">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{total})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="48">
                    <textField>
                        <reportElement uuid="810fbd7d-cb63-42bd-97cb-d6f9edeb736e" mode="Opaque" x="0" y="0" width="46" height="20" backcolor="#CCCCFF"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{totals}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
        <componentElement>
            <reportElement uuid="27791ff5-729e-4c50-8d1d-4559a5b8262c" x="366" y="0" width="43" height="20"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset1" uuid="a3e7cad2-d649-45fc-b5bf-14dbe5a3e135">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{male})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="43">
                    <textField>
                        <reportElement uuid="4702dd4d-9f17-441f-b68a-4996fff701e7" mode="Opaque" x="0" y="0" width="43" height="20" backcolor="#CCCCFF"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{males}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
        <componentElement>
            <reportElement uuid="dcec36d2-f4c3-4762-83b3-fb07f141b74e" x="410" y="0" width="50" height="20"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset2" uuid="abbcec4f-ae32-47b8-b528-5106807d5be1">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{female})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="50">
                    <textField>
                        <reportElement uuid="7699cc1b-a189-43d7-a0a0-943705d2eef9" mode="Opaque" x="0" y="0" width="50" height="20" backcolor="#CCCCFF"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{females}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
        <componentElement>
            <reportElement uuid="84f10209-471d-421f-9917-945d88e91b8c" x="460" y="0" width="92" height="20"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset5" uuid="00626686-ba1d-4540-8e53-5238373bcd8f">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{startDate})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="92">
                    <textField pattern="dd/MM/yyyy">
                        <reportElement uuid="7d96b6c1-58d3-4770-8ce0-48d59f296e0d" x="0" y="0" width="92" height="20"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{startDates}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
        <componentElement>
            <reportElement uuid="9c9c6ecc-d162-4325-adf8-3f357fe5ff3c" x="552" y="0" width="108" height="20"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset6" uuid="22b1cb52-0ccc-461b-ac98-0a991ccd68c2">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{endDate})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="108">
                    <textField pattern="dd/MM/yyyy">
                        <reportElement uuid="8dfab1b7-6bf2-4081-be54-c2147008066e" x="0" y="0" width="108" height="20"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{endDates}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
        <textField>
            <reportElement uuid="c86ce240-52ac-4bc2-931a-1c034a9dd29c" x="0" y="0" width="49" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="912d271c-8ef2-487d-bb8a-58aa09534722" mode="Opaque" x="367" y="200" width="42" height="20" backcolor="#FFFF00"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{totalMale}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement uuid="9da65540-c048-4d9c-9ead-b2fadaa3cefc" mode="Opaque" x="0" y="200" width="318" height="20" backcolor="#FFFF00"/>
            <textElement>
                <font size="12"/>
            </textElement>
            <text><![CDATA[Total]]></text>
        </staticText>
        <textField>
            <reportElement uuid="a728de48-0b0d-4c61-847a-0f422b95f55c" mode="Opaque" x="410" y="200" width="250" height="20" backcolor="#FFFF00"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{totalFemale}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="6b11e458-f835-484f-aae0-53c99fd50fc3" mode="Opaque" x="318" y="200" width="48" height="20" backcolor="#FFFF00"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{totalSize}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="fde9a5f0-7b6f-432d-a217-09f9d5f982e8" x="149" y="0" width="70" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="56e8dcb0-4bff-4b72-90d9-0f023513c69f" x="49" y="23" width="100" height="47"/>
            <textElement>
                <font size="10"/>
            </textElement>
            <textFieldExpression><![CDATA["Year Of Establishment"+$F{yearOfEstablishment}]]></textFieldExpression>
        </textField>
    </band>
</detail>
<columnFooter>
    <band height="45" splitType="Stretch">
        <textField>
            <reportElement uuid="d1b47622-6288-4d54-afb5-3e1b7bb27ce0" mode="Opaque" x="318" y="0" width="49" height="45" backcolor="#FFFFCC"/>
            <textElement/>
            <textFieldExpression><![CDATA[$V{grandTotal}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement uuid="a8ae0b59-1e86-4e54-a68f-1f84bb905441" mode="Opaque" x="0" y="0" width="318" height="45" backcolor="#FFFFCC"/>
            <textElement>
                <font size="12"/>
            </textElement>
            <text><![CDATA[Total continuing Trainees ]]></text>
        </staticText>
        <textField>
            <reportElement uuid="9381e2b9-8a6e-4ac7-b9a9-b0d1536e280d" mode="Opaque" x="367" y="0" width="43" height="45" backcolor="#FFFFCC"/>
            <textElement/>
            <textFieldExpression><![CDATA[$V{grandTotalMale}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="2cb46d61-d435-4742-82a2-77b4d3e6570d" mode="Opaque" x="410" y="0" width="250" height="45" backcolor="#FFFFCC"/>
            <textElement/>
            <textFieldExpression><![CDATA[$V{grandTotalFemale}]]></textFieldExpression>
        </textField>
    </band>
</columnFooter>
<pageFooter>
    <band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
    <band height="42" splitType="Stretch"/>
</summary>

0 个答案:

没有答案