问题
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.
回答1:
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:
- implement a custom query executer to retrieve data from a cached datasource
- generate a rewindable datasource based on the retrieved result set
Thanks to sanda aka shertage on the jasperforge forum for these suggestions.
回答2:
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));
来源:https://stackoverflow.com/questions/7577409/how-to-use-the-same-datasource-twice-in-jasperreports-ireport