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.
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.
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));
Related
There's a working report but I wan't to change the visibility of certain rows based on a completely new DB select that should be executed when the report is created.
It would be ideal, if I could load the values of said select in an array or a list and than simply trigger certain row's visibility by comparing e.g. the Row Id with the values in the array.
Im used to solve a problem like this by creating a View that delivers all the essential information in each row and is used as the main data source but I was wondering if there's an elegant way within crystal reports to solve such a task.
I can think of three ways to include control data like this into the report:
One row of config data: If you can arrange it that your config data query returns one row of data, it can be just added to the data sources of the main report, without any links to tables and views already there.
Config resultset for matching: If you have to match main data results to config values row by row, e.g. by the Row Id you mentioned, add this config query to your report and link it to the main data source accordingly. (You are probably already doing this within your pre-created view on database side.)
Query config by subreport: Most flexible but also time consuming option is to add a subreport in report header, add the config data query and arrange config results into (shared) variables as needed in the subreport. Shared variable values can be used in main report then to control section visibility.
Yes, one of the 3rd-party Crystal Reports UFLs (User Function Libraries) listed here provides such a function.
I am evaluating JasperReports and Jaspersoft Studio for using in the company I work for and I am trying to build a report that contains information from 2 different databases.
I have 2 data adapters configured.
I've my research and found out that the only way to do so is to have either a list, table or subreport in a main report, but I still can't make it work.
I took the subreport approach, I have two reports that work separately, the main one executes this query in the sample DB
select 1 from ORDERS limit 10
The subreport runs this one in a Vertica database I own:
select 1 from my_schema.my_table limit 10
Both of them, as said, run separately.
So I go to the mainreport and add a SubReport element to the ColumnHeader band, then the wizard opens:
In the step 1 I select the subreport from the project
Second step is connection. I have these options:
Same JDBC conection
Use another connection
Use an empty data source
Use a JRDatasourceExpression
Don't use any connection.
The first and third ones are not what I want.
I tried to set the second one, but I could not find a way to select the data adapter that I have configured.
The last one doesn't work ( I get a message saying that my_schema doesn't exists, so I think that it is still trying to access the MainReport database).
Is there anyway I can make a subreport run a query in a different database/datasource from the main report?
I can summarize what I did if anyone has the same issue:
I made a proof of concept (therefore I do not have the code anymore), but I created a JRDataSource class using this tutorial and there I manually access the database and returned the rows. Then I use this as the datasource of my subreport/table.
Not as nice as I wanted, but it is possible
I guess this iReport article is also applicable to reports designed in jaspersoft studio; you just need to define the subreport connection parameter with the given expression.
Perhaps, you can ask for help from two parameters which defined in the master report by yourself. Such as:
$P{MySubreport} with type net.sf.jasperreport.engine.JasperReport;
$P{MyDatasource} with type net.sf.jasperreport.engine.JRDataSource;
Associate these two parameters to your subreport element respectively in attributes 'Expression' and 'Data Source Expression';
Please write your DataSource class that implements interface JRDataSource.
Then, in your servlet class, put your real parameter values(JasperReport for your subreport .jasper file, and your DataSource object) into a parameters Map object, and call JasperFillManager.fillReport().
I'm creating simple report in Jaspersoft Studio 5.6.1 with one table.
Sending data to this report from Java via JRBeanCollectionDataSource.
In report I already can get this data vie fields: report-> DAtaset and Query... -> JavaBean Tab ->
in Class Name write Java class, that comes in list in JRBeanCollectionDataSource -> add selected fields
So now I can display incoming data.
BUT if I want to do it in Table - I need to create Dataset (why?) and choose 'Use same connection used to fill the master report'. Adding same fields to new dataset doesn't help, neither choosing 'Connect to domain' for dataset. No errors displayed.
I need to create Dataset (why?)
In Jasper Reports tables are loosely coupled to the main report, i.e a table requires its own dataset to deal with.
Now say, you have JRBeanCollectionDataSource ready for the report and you wish to use it to fill table with it. Table as I said requires its own datasert, does also require its own datasource.
Now you can either specify a datasource or use same connection to fill the table as that of main report.
For more on jasper report tables visit this link and on java part visit here.
i had a similar problem. I find that you just need is set in the table of your report the REPORT_CONNECTION parameter like say
jaspercomunity
in this.
and then left the value in blank. Later in your java code use a maper object for set the SQL connection to your Data Base, something like this:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=admin");
HashMap<String, Object> hm = new HashMap<String, Object>();
hm.put("REPORT_CONNECTION", conn);
jasperPrint = JasperFillManager.fillReport(reportPath, hm, beanCollectionDataSource);
I am new to JasperReports. I need to design a report where certain columns and rows are dynamic. For this how I have to design the report and after design i want to integrate with my application for fetching data from action class and dto. How to map data for its?
I don't know how dynamic it will be, but it may help you: http://dynamicjasper.com/
It uses JasperReports to generate your report and it also allow you to create your report on the fly.
There are 2 options to map data with the columns. First option is u can pass ur data into data Source binding with the column name as key value pair. And the second option is u can pass the obj of your dto to data source directly in list form.
Use report.setDataSource() for setting the data. In first option make sure your type of the data matches with the column name.
I need to display the xml data in the treelist control. I have one root node, one Child node and further four children for this child node.
I am not able to display it in the treelist. I am using the dataset.readXml method for reading the xml file and giving dataset as a datasource. Here is the code I am following:
DataSet dataSet = new DataSet();
dataSet.ReadXml(#"C:\foldersettings.xml");
treeList2.DataSource = dataSet;
treeList2.PopulateColumns();
treeList2.BestFitColumns();
treeList2.ExpandAll();
Can anyone tell me why am I not getting the data in treelist. I am using DevExpress 9.1 version control.
DataSet dataSet = new DataSet();
dataSet.ReadXml(#"C:\foldersettings.xml");
treeList2.DataSource = dataSet.Table[0];
treeList2.PopulateColumns();
treeList2.BestFitColumns();
treeList2.ExpandAll();
You should also set the KeyFieldName and ParentFieldName properties of the TreeList. Note, these properties should be set to the corresponding field names in the CaseSensitive manner. Also, the TreeList's DataSource should be set to dataSet.Tables[0]. I hope, this will help.
This treeList , from DevExpress will work fine if it will found in your DataSet dataSet in the first column Unique ID's, because it takes as Primary Keys, also, it must find a second column which will be considered like ParentId's.