Search code examples
jasper-reports

How to mark cells red in a table when its value is larger than a pre-defined parameter in Jasper Studio 6.0.1


I put a table in the detail band of a report. The table has four columns. What I want to realize is, set a parameter as threshold value and the parameter is dynamic, all cells in the table which contains value larger than the parameter will be marked as red. How to realize this in JasperReport Studio? My version is 6.0.1


Solution

  • You should use the conditional style on your text fields. 1. Create Style:

    <style name="Detail" fontName="Arial" fontSize="10">
        <conditionalStyle>
            <!-- This is condition, when rows should become red-->
            <conditionExpression><![CDATA[$F{MY_FIELD} > $F{MY_PARAM}]]></conditionExpression>
            <style forecolor="#FF0000"/>
        </conditionalStyle>
    </style>
    
    1. Use this style in your text fields:

          <textField>
              <!-- style="Detail"-->
              <reportElement style="Detail" x="0" y="0" width="143" height="20"/>
              <textFieldExpression><![CDATA[$F{MY_FIELD}]]></textFieldExpression>
          </textField>