[英]BIRT - How to insert different data set rows in different places in a single text element
I'm developing a BIRT report and this is my situation.我正在编写 BIRT 报告,这就是我的情况。 I have one text element, let's say this:
我有一个文本元素,让我们这样说:
blue square: 111
blue triangle: 222
red circle: 333
At the moment is static, and always displays the numbers you see.目前是静态的,并始终显示您看到的数字。 I would like to make the numbers dynamic so I created a SQL query and I have embedded it in a dataset.
我想让数字动态化,所以我创建了一个 SQL 查询并将其嵌入到数据集中。 Let's say this is the output:
假设这是输出:
color shape count
blue square 123
red circle 456
blue triangle 789
I would like to set it up in such a way that each data set row matches the correct row in the text file, so it would become:我想以这样一种方式设置它,即每个数据集行都与文本文件中的正确行相匹配,因此它将变为:
blue square: 123
blue triangle: 456
red circle: 789
And will be automatically updated.并且会自动更新。
I've binded the text element with the dataset and wrote this as a test:我已将文本元素与数据集绑定并将其作为测试编写:
blue square: <VALUE-OF>if (row["color"].toUpperCase() == "BLUE") { row["count"] }</VALUE-OF>
blue triangle: 222
red circle: 333
But when I run the report it doesn't work and the value is blank.但是当我运行报告时它不起作用并且值为空。 What am I doing wrong?
我究竟做错了什么?
Thank you all for the help and let me know if you need more info.感谢大家的帮助,如果您需要更多信息,请告诉我。
You now have a dataset with row[color]
, row[shape]
, row[count]
to simplify your desired output I would add a "computed column" to your dataset.您现在有一个包含
row[color]
、 row[shape]
、 row[count]
的数据集以简化您想要的输出,我会向您的数据集添加一个“计算列”。
eg row[output] = row[color] + ' ' + row[shape] + ': ' row[count]
例如
row[output] = row[color] + ' ' + row[shape] + ': ' row[count]
Once you added the computed column just drag and drop your dataset into your report (where you now have the text element) and delete the unused columns.添加计算列后,只需将您的数据集拖放到您的报告中(您现在拥有文本元素)并删除未使用的列。
Tip: if don't know "computed columns":提示:如果不知道“计算列”:
use Google image search for "bird computed column example"使用 Google 图片搜索“鸟类计算列示例”
the Google text search might get you lost in birt forum lists.谷歌文本搜索可能会让你迷失在 birt 论坛列表中。
Update: It's possible you have some typo in your scriptlet.更新:您的脚本中可能有一些拼写错误。 In BIRT a scriptlet resolves to the last expression within itself.
在 BIRT 中,scriptlet 解析为自身内部的最后一个表达式。 Your scrptlet
<VALUE-OF>if (foo) { bar }</VALUE-OF>
doesn't have a last expression.您的 scrptlet
<VALUE-OF>if (foo) { bar }</VALUE-OF>
没有最后一个表达式。
(It's not wrong but BIRT may not "understand" it this way) (这没有错,但 BIRT 可能不会以这种方式“理解”它)
Try instead <VALUE-OF>var result = ''; if (foo) { result = bar }; result;</VALUE-OF>
尝试改为
<VALUE-OF>var result = ''; if (foo) { result = bar }; result;</VALUE-OF>
<VALUE-OF>var result = ''; if (foo) { result = bar }; result;</VALUE-OF>
<VALUE-OF>var result = ''; if (foo) { result = bar }; result;</VALUE-OF>
and format the scriptlet to several code lines with result;
<VALUE-OF>var result = ''; if (foo) { result = bar }; result;</VALUE-OF>
并将脚本格式化为带有result;
几行代码result;
as last line.作为最后一行。 This is the same as if we consider the scriptlet as a function in some programming language and the last line of the function would be
return result
.这就像我们将 scriptlet 视为某种编程语言中的函数一样,该函数的最后一行将是
return result
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.