如何在 JasperReports/iReport 中使用同一数据源两次
我正在尝试找出如何最好地使用图表和代表相同数据集的表格来制作报告。我需要克服摘要的定位在底部,因此打算使用子报表和表子报表。我正在尝试在一个详细区域中使用两个表格和一个图表。
如果我将 datasourceexpression
设置为 $P{REPORT_DATA_SOURCE}
,则仅图表显示数据(大概是第一个子报表类型项),并且表格为空。好像数据只能消耗一次?
如果我使用数据集来查询数据库,它可以工作,但是它会执行查询三次,每个表/图表一次。这将是一笔巨大的开销。
显然我做得不对,但我找不到任何多次使用同一数据集的示例。
I'm trying to work out how best to do reports with a chart then a table representing the same dataset. I need to overcome the positioning of the summary is at the bottom, so intend to use subreports and table-subreports. I am experimenting with two tables and a chart in one detail band.
If I set the datasourceexpression
for to $P{REPORT_DATA_SOURCE}
only the chart displays data (presumably the first subreport type item) and the tables are empty. Seems the data can be consumed only once?
If I use a Dataset to query the database it works however it executes the Query three times, once for each table/chart. That will be a massive overhead.
Obviously I am not doing this right but I cannot find any examples of using the same dataset more than once.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有简单的答案,所以我提出了一个功能请求 http://jasperforge .org/projects/jasperreports/tracker/view.php?id=5487
建议的解决方法是:
感谢 jasperforge 论坛上的 sanda aka shertage 提供的这些建议。
There is no simple answer so I have raised a feature request http://jasperforge.org/projects/jasperreports/tracker/view.php?id=5487
The suggested workarounds were:
Thanks to sanda aka shertage on the jasperforge forum for these suggestions.
另一种解决方案是克隆数据集:
http://code.google.com/p/cloning/
克隆器 cloner=new 克隆器();
ArrayList 克隆 = cloner.deepClone(getSomeArrayList());
最终 JRDataSource ds = new JRBeanCollectionDataSource(AnotherBean);
HashMap 参数 = new HashMap();
parameters.put("PARAM_A", new JRBeanCollectionDataSource(getSomeArrayList()));
参数.put("PARAM_B", new JRBeanCollectionDataSource(clone));
An alternative solution, cloning the dataset:
http://code.google.com/p/cloning/
Cloner cloner=new Cloner();
ArrayList clone = cloner.deepClone(getSomeArrayList());
final JRDataSource ds = new JRBeanCollectionDataSource(AnotherBean);
HashMap parameters = new HashMap();
parameters.put("PARAM_A", new JRBeanCollectionDataSource(getSomeArrayList()));
parameters.put("PARAM_B", new JRBeanCollectionDataSource(clone));