Jasper iReport 变量 char 的表达式条件

发布于 2024-12-27 12:03:44 字数 289 浏览 2 评论 0原文

我的数据库中有一个列,它是 ColorCode 列(字段名称 $F{COLORCODE} ),其中包含“B”、“R”和“G”等值,我想分别根据它们的颜色计算它们的数量。

所以我有一个名为 countBlue 的变量,变量表达式为 $F{COLORCODE}=='B' 并将其放在列页脚中,但报告计算了该列中的所有内容,包括 R 和 G,我是否错误地执行了比较语句?

我还设置了 countBlue 变量类为 java.lang.Integer,计算为 Count 并将类型重置为 Report

p/s 抱歉英语不好

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扶醉桌前 2025-01-03 12:03:44

您可以使用此表达式(计算计数重置类型报告增量类型:):

<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>

或此(计算重置类型报告; 增量类型):

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

您可以在此处阅读有关变量的信息。

JasperReports 终极指南 说:

计算计数
计数变量在计数中包含非空值
评估变量的主表达式后返回的值,其中
数据源中的每次迭代。计数变量必须始终为
数字类型。但是,它们可以有非数字表达式,如
他们的主要表达方式是因为引擎不关心
表达式类型,但仅计算返回的非空值,
无论其类型如何。

仅变量的初始值表达式
应该是数字并且与变量的类型兼容,因为这
值将被直接分配给计数变量,当
已初始化。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文