简体   繁体   中英

Jasper iReport Variables Expression condition for char

I have a column in my database, which is the ColorCode column (Field name $F{COLORCODE} ) that has values like 'B' and 'R' and 'G', I want to count the amount of them respectively to their color.

So I have variables called countBlue, the variables expression is $F{COLORCODE}=='B' and put it in the Column Footer but the report counted everything including the R and G in that column, did I do the comparison statement wrongly?

also I have set up my countBlue variable class to java.lang.Integer, calculation as Count and reset type as Report

p/s sorry for bad english

You can use this expression ( Calculation : Count ; Reset type : Report ; Increment type : None ):

<variable name="countBlue" class="java.lang.Integer" calculation="Count">
    <variableExpression><![CDATA[$F{COLORCODE}.equals("B") ? "SomeNotNull" : null]]></variableExpression>
    <initialValueExpression><![CDATA[Integer.valueOf(0)]]></initialValueExpression>
</variable>

or this ( Calculation : Nothing ; Reset type : Report ; Increment type : None ):

<variable name="countBlue" class="java.lang.Integer">
    <variableExpression><![CDATA[$F{COLORCODE}.equals("B") ? $V{countBlue} + 1 : $V{countBlue}]]></variableExpression>
    <initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>

You can read about variables here .

The JasperReports Ultimate Guide says:

Calculation Count
A count variable includes in the count the non-null values returned after evaluating the variable's main expression, with every iteration in the data source. Count variables must always be of a numeric type. However, they can have non-numeric expressions as their main expression since the engine does not care about the expression type, but only counts for the non-null values returned, regardless of their type .
Only the variable's initial value expression should be numeric and compatible with the variable's type, since this value will be directly assigned to the count variable when initialized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM