我在Cross选项卡中有一个Column测量值,当列值发生变化时,需要对其进行不同的样式设置。对于实例,我当前的输出看起来像这样
我试图以这种方式为列着色
此处的输出格式为xls。
SHIPCITY是一个父列标题,在该标题下面有SHIPADRESS。
下面是生成当前输出的jrxml。您可以使用它重现问题。
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0 -->
<!-- 2017-09-04T18:07:58 -->
<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="ConditionalStyling" pageWidth="1400" pageHeight="842" columnWidth="1400" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" uuid="c83c5a57-1109-4513-a122-d0bfbf7fd308">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<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"/>
<style name="Crosstab_CH" 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="Crosstab_CG" 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="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<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="Crosstab_CD" 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" mode="Opaque" forecolor="#000000" backcolor="#F7211E"/>
<queryString>
<![CDATA[select * from orders order by customerid, shipcountry , shipcity , shipaddress ]]>
</queryString>
<field name="ORDERID" class="java.lang.Integer"/>
<field name="CUSTOMERID" class="java.lang.String"/>
<field name="EMPLOYEEID" class="java.lang.Integer"/>
<field name="ORDERDATE" class="java.sql.Timestamp"/>
<field name="REQUIREDDATE" class="java.sql.Timestamp"/>
<field name="SHIPPEDDATE" class="java.sql.Timestamp"/>
<field name="SHIPVIA" class="java.lang.Integer"/>
<field name="FREIGHT" class="java.math.BigDecimal"/>
<field name="SHIPNAME" class="java.lang.String"/>
<field name="SHIPADDRESS" class="java.lang.String"/>
<field name="SHIPCITY" class="java.lang.String"/>
<field name="SHIPREGION" class="java.lang.String"/>
<field name="SHIPPOSTALCODE" class="java.lang.String"/>
<field name="SHIPCOUNTRY" class="java.lang.String"/>
<summary>
<band height="300">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<crosstab>
<reportElement x="0" y="0" width="1400" height="300" uuid="34cf7e8d-c567-485d-85a7-798c27118f97">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
</reportElement>
<crosstabHeaderCell>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="90" height="40" uuid="de2c1860-2c17-451c-93c1-691b7a2d52c6"/>
<text><![CDATA[CUSTOMER_ID]]></text>
</staticText>
</cellContents>
</crosstabHeaderCell>
<rowGroup name="CUSTOMERID" width="90">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{CUSTOMERID}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="5b8cdacd-7f44-4dcf-8db0-6b6c58c3fb32"/>
<textFieldExpression><![CDATA[$V{CUSTOMERID}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="0" height="0" uuid="08c3c9ff-49ec-435c-9fb9-10a97aeb16ff"/>
<text><![CDATA[Total CUSTOMERID]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="SHIPCITY" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{SHIPCOUNTRY}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement style="Style1" x="0" y="0" width="100" height="20" uuid="f68a5ef8-d957-4568-b895-93907688b107"/>
<textFieldExpression><![CDATA[$V{SHIPCITY}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CG">
<staticText>
<reportElement x="0" y="0" width="0" height="0" uuid="9893aa3b-7eae-42de-b18d-30a92e1e6580"/>
<text><![CDATA[Total SHIPCITY]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<columnGroup name="SHIPADDRESS" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{SHIPADDRESS}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="969f7bc4-600e-4310-aa3f-526c278b6fde"/>
<textFieldExpression><![CDATA[$V{SHIPADDRESS}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<staticText>
<reportElement x="0" y="0" width="0" height="0" forecolor="#FFFFFF" uuid="08ba2a79-077d-4f94-bc55-62939d55e557"/>
<text><![CDATA[Total SHIPADDRESS]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="ORDERID_MEASURE" class="java.lang.Integer">
<measureExpression><![CDATA[$F{ORDERID}]]></measureExpression>
</measure>
<crosstabCell width="100" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="2ea2bac8-82f5-42b8-a6fe-2a397cadc9b2"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="SHIPADDRESS">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="46cc1294-ec97-4dcf-9189-f77fb9e87538"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="SHIPCITY">
<cellContents mode="Opaque" style="Crosstab_CG">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="4bade212-3c6d-4027-bb5f-9e22ee527401"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="CUSTOMERID">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="58c77e0a-d003-4f5f-9f0e-8f6e0e5a12d5"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="CUSTOMERID" columnTotalGroup="SHIPADDRESS">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="163a57aa-ff00-4362-b078-8106fb513043"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="CUSTOMERID" columnTotalGroup="SHIPCITY">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="de152f44-e188-42ef-9e22-7e8346e0f860"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
我可以创建两个条件,但无法想到在条件表达式中应用的逻辑。关于如何实现这种条件造型的任何想法?
答案 0 :(得分:0)
这很棘手。我在我的SQL中添加了一个用于着色的列。使用dense_rank()函数我给结果排名并将它们分组在国家名称上。所以基本上那些具有相同国家名称的行具有相同的排名,然后我根据国家名称对此进行排序。
在碧玉一边。我在列组中添加了这个着色列,并将其宽度设置为零,然后将条件样式逻辑添加到奇数和偶数值。这是我正在寻找的逻辑。