Hi,
Today, I wanted to have conditional colors based on aggregated value(s) of a data set on Table component.
Unless you add below property to the report the calculations can not be used for styling.
The property you have to add is :
Property:
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
Sample Screen shot :
JRXML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
<!-- 2016-06-27T18:43:11 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" uuid="4bdc9118-0a52-4a39-bed1-b1ee9813e230">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<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"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.freeze.row" value="2"/>
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Style1">
<conditionalStyle>
<conditionExpression><![CDATA[$V{totalchildren1}>=200 &&$V{totalchildren1} <=1000]]></conditionExpression>
<style backcolor="#D43511"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$V{totalchildren1}>1000]]></conditionExpression>
<style backcolor="#15C21B"/>
</conditionalStyle>
</style>
<subDataset name="Dataset1" uuid="a03b4f51-6c4c-46cd-8545-7f8f7198dc1e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<queryString>
<![CDATA[SELECT state_province,member_card, SUM (total_children) totalChildren
FROM customer
GROUP BY state_province, member_card ORDER BY state_province ]]>
</queryString>
<field name="state_province" class="java.lang.String"/>
<field name="member_card" class="java.lang.String"/>
<field name="totalchildren" class="java.lang.Long"/>
<variable name="totalchildren1" class="java.lang.Long" resetType="Group" resetGroup="Group1" calculation="Sum">
<variableExpression><![CDATA[$F{totalchildren}]]></variableExpression>
</variable>
<group name="Group1">
<groupExpression><![CDATA[$F{state_province}]]></groupExpression>
</group>
</subDataset>
<queryString>
<![CDATA[SELECT 1 as One ]]>
</queryString>
<field name="one" class="java.lang.Integer"/>
<background>
<band splitType="Stretch"/>
</background>
<summary>
<band height="60" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="555" height="60" uuid="71b1af30-df05-4763-a3d7-f30a00ca334a">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="254a3472-9e0d-4b10-9082-19e671ae41da">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="210" uuid="4e78f62c-6fa9-45c7-bf0f-148898adb85e">
<jr:groupHeader groupName="Group1">
<jr:cell height="30">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField>
<reportElement x="0" y="0" width="210" height="30" uuid="ff2110e4-2f89-4222-ae28-2ff85db11aec"/>
<box leftPadding="5"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{state_province}]]></textFieldExpression>
</textField>
</jr:cell>
</jr:groupHeader>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" x="0" y="0" width="210" height="30" uuid="b9713338-10ba-42b9-8794-786ea144c363"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[State]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30"/>
</jr:column>
<jr:column width="160" uuid="ea577695-22fb-4fa8-b7d7-55ae8f079797">
<jr:groupHeader groupName="Group1">
<jr:cell height="30"/>
</jr:groupHeader>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" x="0" y="0" width="160" height="30" uuid="80e3a954-86db-4627-a841-7635786214a1"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[Member Card]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="160" height="30" uuid="67a36de8-d542-4d5c-a352-d2270bb9facb"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{member_card}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="185" uuid="115b86b4-ec3d-4d3b-b855-d5ef38e9c0d4">
<jr:groupHeader groupName="Group1">
<jr:cell height="30">
<textField evaluationTime="Group" evaluationGroup="Group1">
<reportElement style="Style1" mode="Opaque" x="0" y="0" width="185" height="30" uuid="eae7a88f-2f46-4266-90d2-1b5f2a0dc451"/>
<box>
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{totalchildren1}]]></textFieldExpression>
</textField>
</jr:cell>
</jr:groupHeader>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" x="0" y="0" width="185" height="30" uuid="ffce4b15-e7ae-4b07-94a9-5f713725dd25"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[Total Children]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement mode="Opaque" x="0" y="0" width="185" height="30" uuid="9080cc65-6f3d-4a2d-943f-6e4942c18710"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{totalchildren}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>
Reference :
http://stackoverflow.com/questions/12269736/using-variables-in-conditional-style
Today, I wanted to have conditional colors based on aggregated value(s) of a data set on Table component.
Unless you add below property to the report the calculations can not be used for styling.
The property you have to add is :
Property:
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
Sample Screen shot :
JRXML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
<!-- 2016-06-27T18:43:11 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" uuid="4bdc9118-0a52-4a39-bed1-b1ee9813e230">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<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"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.freeze.row" value="2"/>
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Style1">
<conditionalStyle>
<conditionExpression><![CDATA[$V{totalchildren1}>=200 &&$V{totalchildren1} <=1000]]></conditionExpression>
<style backcolor="#D43511"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$V{totalchildren1}>1000]]></conditionExpression>
<style backcolor="#15C21B"/>
</conditionalStyle>
</style>
<subDataset name="Dataset1" uuid="a03b4f51-6c4c-46cd-8545-7f8f7198dc1e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<queryString>
<![CDATA[SELECT state_province,member_card, SUM (total_children) totalChildren
FROM customer
GROUP BY state_province, member_card ORDER BY state_province ]]>
</queryString>
<field name="state_province" class="java.lang.String"/>
<field name="member_card" class="java.lang.String"/>
<field name="totalchildren" class="java.lang.Long"/>
<variable name="totalchildren1" class="java.lang.Long" resetType="Group" resetGroup="Group1" calculation="Sum">
<variableExpression><![CDATA[$F{totalchildren}]]></variableExpression>
</variable>
<group name="Group1">
<groupExpression><![CDATA[$F{state_province}]]></groupExpression>
</group>
</subDataset>
<queryString>
<![CDATA[SELECT 1 as One ]]>
</queryString>
<field name="one" class="java.lang.Integer"/>
<background>
<band splitType="Stretch"/>
</background>
<summary>
<band height="60" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="555" height="60" uuid="71b1af30-df05-4763-a3d7-f30a00ca334a">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="254a3472-9e0d-4b10-9082-19e671ae41da">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="210" uuid="4e78f62c-6fa9-45c7-bf0f-148898adb85e">
<jr:groupHeader groupName="Group1">
<jr:cell height="30">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField>
<reportElement x="0" y="0" width="210" height="30" uuid="ff2110e4-2f89-4222-ae28-2ff85db11aec"/>
<box leftPadding="5"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{state_province}]]></textFieldExpression>
</textField>
</jr:cell>
</jr:groupHeader>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" x="0" y="0" width="210" height="30" uuid="b9713338-10ba-42b9-8794-786ea144c363"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[State]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30"/>
</jr:column>
<jr:column width="160" uuid="ea577695-22fb-4fa8-b7d7-55ae8f079797">
<jr:groupHeader groupName="Group1">
<jr:cell height="30"/>
</jr:groupHeader>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" x="0" y="0" width="160" height="30" uuid="80e3a954-86db-4627-a841-7635786214a1"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[Member Card]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="160" height="30" uuid="67a36de8-d542-4d5c-a352-d2270bb9facb"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{member_card}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="185" uuid="115b86b4-ec3d-4d3b-b855-d5ef38e9c0d4">
<jr:groupHeader groupName="Group1">
<jr:cell height="30">
<textField evaluationTime="Group" evaluationGroup="Group1">
<reportElement style="Style1" mode="Opaque" x="0" y="0" width="185" height="30" uuid="eae7a88f-2f46-4266-90d2-1b5f2a0dc451"/>
<box>
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{totalchildren1}]]></textFieldExpression>
</textField>
</jr:cell>
</jr:groupHeader>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" x="0" y="0" width="185" height="30" uuid="ffce4b15-e7ae-4b07-94a9-5f713725dd25"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[Total Children]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement mode="Opaque" x="0" y="0" width="185" height="30" uuid="9080cc65-6f3d-4a2d-943f-6e4942c18710"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{totalchildren}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>
Reference :
http://stackoverflow.com/questions/12269736/using-variables-in-conditional-style
No comments:
Post a Comment