Using conditional style variables

I have a title bar with a text box containing a computed variable $V{avg_perc}. The text field has the estimated time set in the Report , the same for resetType variables . Now I'm trying to set the background color of this field with a conditional style, but I get an error all the time:

Invalid expression: !Double.isNaN($V{avg_perc}) && $V{avg_perc} >= 0.8

I do the same with the same conditional style in the column footer, and it works without any problems, even if I set the estimated time for this field in the Report too.

After deletion, !Double.isNaN($V{avg_perc})I no longer get the error, but the expression still does not work. My field is red, which is the primary color when none of the conditions apply, no matter what the meaning $V{avg_perc}. However, it still works in the Footer column. This is my style:

<style name="avg_color" mode="Opaque" backcolor="#FF0000" pdfFontName="Helvetica-Bold">
    <conditionalStyle>
        <conditionExpression><![CDATA[$V{avg_perc} >= 0.8]]></conditionExpression>
        <style backcolor="#008000"/>
    </conditionalStyle>
    <conditionalStyle>
        <conditionExpression><![CDATA[$V{avg_perc} >= 0.6 && $V{avg_perc} < 0.8]]></conditionExpression>
        <style backcolor="#FFCC00"/>
    </conditionalStyle>
</style>

Used fields and variables for this:

<field name="perc" class="java.lang.Double"/>
<variable name="avg_perc" class="java.lang.Double" calculation="Average">
    <variableExpression><![CDATA[$F{perc}]]></variableExpression>
</variable>

Any idea how to make this thing work? I am using JasperReports and iReport in version 3.7.4.

+5
source share
3 answers

I finally found a solution to my problem. Adding

<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>

at the report level, causes the conditional style to be executed when the element is evaluated. See this answer in the Jaspersoft community for more information.

+8

ireport.

.: markup = styled selected

fied. :

($F{fila1}.equals("c") ? "<style forecolor='red'>"+ $F{fila1}+"</style>" : $F{fila1})

xml

<textFieldExpression><![CDATA[($F{fila1}.equals("c") ? "<style forecolor='red'>"+ $F{fila1}+"</style>" : $F{fila1})]]></textFieldExpression>
+2

Change this code based on your requirement

<style name="alternateStyle" fontName="Arial">
    <conditionalStyle>
        <conditionExpression><![CDATA[new Boolean($V{AMOUNT}.intValue() == 0)]]></conditionExpression>
        <style mode="Opaque" backcolor="#FF0000" isBold="true"/>
    </conditionalStyle>
</style>

And also link to this link: Link

0
source

All Articles