JasperReport &填充成分
JasperReports 新手在这里。我已阅读 教程 和 快速参考并阅读了许多有关 JR 的文章,现在已经使用 iReport 报表设计器一天左右了。
我认为我感到窒息的最后一组主要概念与图表组件及其数据之间的关系有关。尽管很容易找到其中每一个的定义,但似乎很少有实践文档显示它们在有意义的应用程序中如何相互关联。
- 报表字段
- 报表参数
- 报表变量
- 数据
集 通过使用 iReport,似乎字段、参数和变量可以存在于报表级别,也可以放置在数据集中。但是我对字段、参数和变量的理解非常模糊,而且我对它们与数据集如何关联的理解也非常不稳定。
使用数据集作为轻微的延续,我很难看到“穿过树木的森林”以及图表组件(例如饼图、表格等)如何“馈送”或“注入”其数据。
Soo...我想到了一个例子,如果得到回答,将为我将所有事情联系在一起(我相信!)。假设我有两个图表组件,一个文本字段和一个饼图。我希望饼图显示在文本字段下方,如下所示:
The author of this report is: <value supplied by the data source>
<pie chart here>
因此,在“填充时间”(我认为我正确使用了...),报告将“填充”为报告作者的姓名(字符串),以及由 2 个饼图切片组成的饼图:第 1 个切片的值为 75,标签/键为“Eloi”,第二个切片的值为 25 和标签/键“莫洛克”。如果我在这里没有使用正确的 JR 术语,我想要实现的是一个包含两个切片的填充时间饼图:一个“Eloi”切片消耗图表的 75%,一个“Morlocks”切片消耗图表的 25%。图表。
如果有人可以解释或提供如何设置此类图表的代码(Java/JRXML)片段,我认为这将有助于连接所有点并帮助我理解组件如何填充数据。预先感谢您的任何和所有帮助!
JasperReports newbie here. I have read the tutorial and the quick reference and read up on a number of articles regarding JR, and have now been playing around with the iReport report designer for a day or so.
I think the last major set of concepts I am choking on have to do with the relationship between chart components and their data. Although it is easy to find definitions for each of these, there seems to be very little practicle documentation showing how they relate to one another in a meaningful application.
- Report Fields
- Report Prameters
- Report Variables
- Datasets
By playing around with iReport it seems that Fields, Parameters and Variables can exist at the report-level, as well as being placed inside of Datasets. But my understanding of when something is a Field vs. Parameter vs. Variable is very fuzzy, and my understanding of how they relate to Datasets is also very shaky.
Using Datasets as a slight segue, I'm having a tough time seeing the "forest through the trees" with how chart components (such as pie charts, tabls, etc.) get "fed" or "injected with" their data.
Soo... I thought of an example that, if answered, would tie everything together for me (I believe!). Let's say I had two chart components, a text field and a pie chart. I want the pie chart to appear below the text field like so:
The author of this report is: <value supplied by the data source>
<pie chart here>
So, at "fill time" (I think I'm using that correctly...), the report will be "filled" with the name of the report's author (a String), as well as a pie chart comprised of 2 pie slices: 1 slice with a value of 75 with a label/key of "Eloi" and a 2nd slice with a value of 25 and a label/key of "Morlocks". If I am not using the correct JR terminology here, what I am trying to achieve is a fill-time pie chart with two slices: an "Eloi" slice consuming 75% of the chart, and a "Morlocks" slice consuming 25% of the chart.
If someone can explain or give code (Java/JRXML) snippets for how to set this kind of chart up, I think it will help connect all the dots and help me understand how components get filled with data. Thanks in advance for any and all help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将参数视为最终用户在运行时向报表提供的内容。例如,您提供将在查询中使用的 StartDate 和 EndDate。您感兴趣的开始日期是您知道的,它不是由数据源提供的。 (这个想法有多种变化:也许您的应用程序根据您的登录了解有关您的信息,并将这些信息作为参数提供。但同样,这些是在执行报告之前已知的信息。)
将字段视为来自的数据从您的数据源返回。这就是你想要学习的东西。例如,您运行如下查询:
selectpolitical_group, gullibility from mytable where the_date > $P{StartDate}
大概您会为 StartDate 输入值“802701”,然后得到如下结果:
将变量视为操作此原始数据的一种方式。它们可以计算总计和小计,以及逐行计算(如字符串操作)或更复杂的计算(如运行总计)。
看看我几年前发布的饼图报告: http://mdahlman.wordpress.com/2009/05/02/limiting-pie-pieces/
它有你想要的主要想法。我将标题直接放入图表中,而不是作为单独的字段。这将是一个非常简单的改变。同样,您可以将标题更改为“此报告的作者是:$P{TheAuthor}”,然后在运行时将该参数传递给报告。
也可以在报告标题中使用字段而不是参数。但通常情况下这是没有意义的。这些字段在数据集中将有许多值。标题中属于哪一个?在上面的例子中,“Eloi”和“Morlock”是字段,它们在报告标题中确实没有意义。 (当然,您可以想象特殊情况。您可以将所有political_group值连接成一个字符串并将其放入报告标题中。但在绝大多数情况下,这是不合理的。)
祝您好运。
Think of parameters as things that the end user supplies to the report at runtime. For example, you supply a StartDate and an EndDate that will get used in a query. The start date that you are interested in is something you know, it's not provided by the data source. (There are variations on this idea: maybe your application knows things about you based on your login, and it supplies these as parameters. But again, these are things known before the report is executed.)
Think of the fields as the data that comes back from your data source. This is the stuff that you want to learn. For example, you run a query like this:
select political_group, gullibility from mytable where the_date > $P{StartDate}
Presumably you would input a value of '802701' for the StartDate and then get results like this:
Think of variables as a way to manipulate this raw data. They can calculate totals and subtotals as well as line-by-line calculations like string manipulation or more complex things like running totals.
Take a look at this pie chart report I posted a couple of years ago: http://mdahlman.wordpress.com/2009/05/02/limiting-pie-pieces/
It has the main ideas you want. I put the title directly into the chart rather than as a separate field. That would be a very simple change. Likewise, you could change the title to "The author of this report is: $P{TheAuthor}" and then pass that param to the report at runtime.
Using a field in the report title rather than a parameter is possible also. But typically it doesn't make sense. The fields will have many values in the data set. Which one belongs in the title? In the case above "Eloi" and "Morlock" are fields, and they really don't make sense in the report title. (You can imagine special cases, of course. You could concatenate all of the political_group values into a single string and put that in the report title. But in an overwhelming majority of cases this won't be reasonable.)
Good luck.