lionelv Posted November 2, 2006 Share Posted November 2, 2006 Hi all, I've searched through the documentation and this has been discussed in various ways but I haven't got a grip on the best approach or how I should do this. I have a report that I use fillReport(JasperReport jasperReport, java.util.Map parameters, java.sql.Connection conn) on. However, I also want to add 1 or more rows to a separate section in the report from data that is generated in my Java program and is not in the database. I can store this data as any implementation of a Collection if necessary. Each row is a pair such as: theta(1) someDoubleValue1theta(2) someDoubleValue2 What is the best approach to do this? The desired result is very roughly like this: //data from some sort of list:theta(1) value..... ... //data retrieved from database that has several columnscolumn1 column2 column3 . . . . Thanks Lionel. Link to comment Share on other sites More sharing options...
lucianc Posted November 2, 2006 Share Posted November 2, 2006 You can achieve this by writing a subreport for the "theta" rows, send the data to the (master) report as a parameter, wrap it in a JRBeanCollectionDataSource or JRMapCollectionDataSource and use this data source to fill the subreport. HTH,Lucian Link to comment Share on other sites More sharing options...
lionelv Posted November 2, 2006 Author Share Posted November 2, 2006 Hi lucianc, I thought that I would start by making a blank report and trying to pass in a JRMapCollectionDataSource which is initialised with an ArrayList containing one String element. However I ended up with:java.io.StreamCorruptedException: invalid stream header Do you happend to know what might cause this? Can we elaborate on how this works, the API documentation I have found doesn't have any detail :(. So if I pass in a JRMapCollectionDataSource successfully how do I access the fields, what do they show up in ireport as? Do they have names? How are the names determined? Getting a bit further ahead and on the topic of adding the theta data to a subreport do I add JRMapCollectionDataSource to the parameters or do I add the ArrayList and then when I pass it to the subreport I select "Use Custom Datasource" and provide new JRMapCollectionDataSource($P{thetaCollection})as the data source? thanks Lionel. Link to comment Share on other sites More sharing options...
lucianc Posted November 2, 2006 Share Posted November 2, 2006 Can you post the full exception stack trace and relevant JRXML/code fragments? I'm not an iReport expert, so I can only tell how things would be done from the JasperReports perspective:Create a java.util.Map parameter in your master report:Code:<parameter name="subreportData" class="java.util.Map" isForPrompting="false"/>Construct the collection of maps in your Java code and send it to the report:Code:[code]List subreportData = new ArrayList();for (..){ Map data = new HashMap(); data.put("myField1", value1); data.put("myField2", value2); subreportData.add(data);}..parameters.put("subreportData", subreportData); Create a data source for the subreport:Code:[code]<subreport> <dataSourceExpression> new JRMapCollectionDataSource($P{subreportData}) </dataSourceExpression></subreport>Declare your fields in the subreport:Code:[code]<field name="myField1"/><field name="myField2"/>[/ul] HTH,Lucian Link to comment Share on other sites More sharing options...
lionelv Posted November 3, 2006 Author Share Posted November 3, 2006 lucianc wrote:Can you post the full exception stack trace and relevant JRXML/code fragments? What I'll do is follow the instructions you have posted here and see how I go. If I still have a problem then I will come back with the stack trace. It may be a day or a few days before I get to work on it again as it is only my casual job. Hopefully tonight though (which is 10 hours away for me :)). Thanks Lionel. Link to comment Share on other sites More sharing options...
lionelv Posted November 6, 2006 Author Share Posted November 6, 2006 I got it working pretty quickly using your post as a guide. I've forgotten what the exception was from that I posted, d'oh, I was going to post it for future searches. It was something like passing the wrong class type in. Anyway, for anyone else who might read this: To use a custom JRDataSource in a sub-report including the implementations of JRDataSource provided such as JRMapCollectionDataSource you design your sub-report as normal. Under data source you specify "Custom data source" and delete all the stuff about factory classes etc. You then add the fields to the report that you are going to send in the data source. You need to add a parameter to the master report in iReport of type Object. When you add your sub-report you can look at the properties and tell it where to get the data-source. Tell it custom data source and then in the second text box type (for a JRMapCollectionDataSource): new JRMapCollectionDataSource(java.util.ArrayList(parameterObject)) The parameter you pass in must be a List (or Collection, sorry I can't remember because I don't have iReport on this computer but List definitely works) of Map instances. Now each instance of Map will have key-value pairs. The key is the field name in the sub-report and the value is the field value. If anyone is reading this and needs further advice please email me lionelv at gmail dot com Lionel. Link to comment Share on other sites More sharing options...
atanupanda Posted February 6, 2007 Share Posted February 6, 2007 HiThis is Atanu. I am very new in ireport and also in java environment. In the ireport I have designed a template .like this.please look on attach file size=150]C:Documents and SettingsAtanuMy Documentsgraph.jpegNow I want to plot a line graph on the basis of the each data like t1 t2 ---t5 and lcl, ucl, actual value for each row.That I have done. Now my problem is that I have to change the color of points of t1 t2 ---t5 on the basis of Lcl and Ucl . If the value of t1 ,or t2 or ----t5 are between Ucl and Lcl the color will be blue. And if it out side of Lcl and Ucl then it will be red..I want the following figure. Where the upper bold line is Ucl and lower bold line isLcl size=150]C:Documents and SettingsAtanuMy Documentsdata.jpeg Actually I have got a information that for that I have to write a customizer class for chart. Also I have write it . Code:Now this customize class ok running successfully with creating jar files.Now I want to create a logic to check the value of t1 t2 t3 t5 with respect to UCL and LCL. How can I fetch data from report.Or is there any other way to do this.Is there any way to pass value from iReport to customizer class ? What should I do. Please please help me. It’s urget for me. Any help would be greatly appreciated. Thanks in advance. [file name=query-37ab101e3a539a71be9c962f72749d92.doc size=49152]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/query-37ab101e3a539a71be9c962f72749d92.doc[/file] [file name=query-f43e5eff273aeb77d1364cc5f09484dc.doc size=49152]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/query-f43e5eff273aeb77d1364cc5f09484dc.doc[/file] size=159]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/graph-4af1b993db50050c28850a4d8438e325.JPG Link to comment Share on other sites More sharing options...
shainaztamboli Posted July 14, 2010 Share Posted July 14, 2010 hi,can u give me a a detailed information related to the passing a collection as a parameter. I followed above steps told by lionelv.but not working for me. please tell me its very urgent. Regards,Shainaz Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now