Integrate Charts in Jasper Reports +JSF 2.0 - Ramki Java Blog
Integrate Charts in Jasper Reports +JSF 2.0 - Ramki Java Blog
http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-j...
In this post we will walk through how to integrate Charts (JFreeChart) into Jasper Report framework. JasperReports is the world's most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixelperfect documents that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Xlsx, Docx, Pptx, Odf Check my Introduction to Jasper Reports and Sub-report with jasper Report posts. 2-ways to Integrate the Charts/Graphs into Jasper Reports 1. Use JFreeChart API inside Jasper Report to generate the Charts while generating reports 2. Use any 3rd party Java Libraries to create the chart and stored in In-memory Image object (or) stored in file. then pass the Image/file to Jasper Report. then embed the Image into Report. (check here) In this post we going to use 1st option. In Jasper Report use JFreeChart Components to make charts. In my next post we will see the 2nd way to generate the charts in reports. I ll create one sample application (Progress Report) to demonstrate the Integrate the charts in reports. I have Student Bean contain name, roll No, image and List of Semester paper beans. In Semester paper bean contain name of the paper and mark(score). Student.java
view plain print ?
179674
I'm on
Rama krishnnan E P
01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15.
import java.util.List; /** * * @author ramki */ public class Student { private String name; private String rollNo; private String imagePath; private List<semesterpaper> listOfSemesterPaper; // getters and setters } </semesterpaper>
View all
SemesterPaper.java
view plain print ?
01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14.
Rama krishnnan E P
29 vdeos | 573 suscriptores
Subscribe
Martin Murciego
public SemesterPaper(String name, double mark) { this.name = name; this.mark = mark; } // getters and setters }
1 de 5
http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-j...
Create the Report we can use either iReport Standalone version or Jasper report Net-beans plugins to create the jasper Reports. Create empty reports and create the fields and these fields are match with Student bean property variables. here name,rollNo and imagePath are String. so no need to change the data type of field. but listOfSemesterPaper is List. so change the data type of the field to List.
JSF + JPA + JasperReports (iReport) Part 1 Hi in this post we will see the overview of JasperReports and how to integrate into JSF application. JasperReports is the world's mo... Virtual Host + Apache httpd server + Tomcat + mod_jk
then drag Image component and static text component for making general report like this
connector In my last post ( Virtual Host in Tomcat ) we discussed about how setup the virtual host in Tomcat. Its cost effective technique because on... JSF + JPA + JasperReports (iReport) Part 2 In this post is a continuation of Jasper Report Part 1 . here we will discuss about some advanced jasper report concepts like passing com... How to do SSH Tunneling (Port Forwarding) Screen-cast In this post we will see how ssh works?, what is SSH tunneling? what is important of ssh tunnels and how to setup the ssh tunnel. When SS... Running Multiple Tomcat Instances on Single Machine In this post we will see how to run multiple tomcat instances on single machine and under single user account. We first see the tomcat di...
here name and rollNo fields are dragged into report canvas, then drag the Image component and change the expression of Image component to imagePath field. Now we ready for bring the Chart component. But chart data are stored in listOfSemesterPaper field. Its List. So we can't use directly. so we going to create sub data set from main data set. so create sub dataset named "ChartDataset". and In sub data set create another 2 fields match with SemesterPaper bean. here name is String and mark is double.
Now drag the chart and choose the chart type. here i chosen Bar chart. its poped up the wizard. we need to choose Data set. here we need to choose "ChartDataset" sub data set, which one we created. then select the Category and Value property of Charts. here name is category and mark is value. (see the screenshot)
2 de 5
http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-j...
and final step is we need to explicitly mention how main data set is divied into sub data set. In sub data set "ChartDataset" is take value of listOfSemesterPaper field. this fields is List. so we need to wrap into JRBeanCollectionDataSource.
screencast (22)
Tomcat (6) clustering (5) tomcat
2013 (2) 2012 (13) that's it. now compile the report and generate the .jasper format. then integrate into Netbeans project. December (1) November (1) October (2) DemoBean.java
view plain print ?
September (2) Integrate Chart Image into Jasper Report Part - 2 Integrate Charts in Jasper Reports +JSF 2.0 June (2) April (2) March (1) February (1) January (1)
01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43.
@ManagedBean @SessionScoped public class DemoBean { private List<student> listOfStudent; public DemoBean() { listOfStudent = new ArrayList<student>(); Student student = new Student(); student.setName("Ramki"); student.setRollNo("02CS24"); student.setImagePath("C:\\Users\\ramki\\Downloads\\ramki.jpg"); List<semesterpaper> listOfSemsterPaper = new ArrayList<semesterpaper>(); listOfSemsterPaper.add(new SemesterPaper("S/W Engg", 50.6)); listOfSemsterPaper.add(new SemesterPaper("Java", 88.6)); listOfSemsterPaper.add(new SemesterPaper("Data Struct", 66.6)); listOfSemsterPaper.add(new SemesterPaper("Algorithm", 77.6)); listOfSemsterPaper.add(new SemesterPaper("Lab 1", 90.6)); listOfSemsterPaper.add(new SemesterPaper("Lab 2", 99.6)); student.setListOfSemsterPaper(listOfSemsterPaper); listOfStudent.add(student);
} public String pdf() throws JRException, IOException { JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listOfStudent); String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports /chartReports.jasper"); JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap(), beanCollectionDataSo urce); HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getE xternalContext().getResponse(); httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf"); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); FacesContext.getCurrentInstance().responseComplete(); return null; } } </semesterpaper></semesterpaper></student></student>
index.xhtml
view plain print ?
<h:head> <title>Facelet Title</title> </h:head> <h:body> <h:form> Generating Report : <h:commandbutton action="#{demoBean.pdf()}" value="Generate"> </h:commandbutton></h:form> </h:body>
3 de 5
http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-j...
JSF JPA JasperReports (iReport) Part 2 ian Hi, yes i have getters and setters, the error from the firstName is now working but when i added the...
4 hours ago The last comments for
JSF JPA JasperReports (iReport) Gabriel Instalacion rapida y sencilla sudo apt-get install libapache2-mod-jk
6 hours ago The last comments for
JSF JPA JasperReports (iReport) Part 2 Ramki 53p Hello Ian, Thanks, yes i ll help. So what is ur bean variable 'firstName'? and r u...
23 hours ago
ian Good Day! Great Tutorial! I watched your video on youtube. Anyway can you help me? I followed your tutorial...
23 hours ago The last comments for
Comments (8)
Sort by: Date Rating Last Activity Andi 25 weeks ago
Login
Really thanks for this tutorial! Right now I need to do some research about Jasperreports and I'm trying to follow this tutorial by making some adjustments because I use Eclipse and JasperStudio. Can I have the source code of this tutorial? Thanks mate!
Reply
Report
Comments by IntenseDebate
Ramki 53p 25 weeks ago Hello Andi, I upload the project code into my github page : https://github.com/ramkicse/ChartJasperReport
Reply
+2
Report
Posts Comments
Sweet, very nice Ramki. It is really good video and helped us a lot. Thank you very much for this. I requested this tutorial last week and you mad eit with in a week, perfecto !!!!
Reply
Report
Hi Ramki, I'm having some problems modifying this tutorial regarding the datasource for a chart, if you have a sec would you mind looking at my stackoverflow post? http://stackoverflow.com/questions/12538967/jaspe... And for other users: I had another problem adding more students to the list and received a good answer, so if you'd like to do the same to your project check out the solution below: http://stackoverflow.com/questions/12526675/using...
Reply
Delivered by FeedBurner
Report
+2
Hello eljaydub, sorry for late reply. i was out of station. yes that's correct u should use detail band for more iterating purpose. because detail band inbuilt capable for iterating. R u still have any problem?
Reply
Report
Verigina 5 weeks ago Hi Ramki, I am trying your tutorial but S/W Engg, Java or Lab 1 moves up. They are not under the bar item. How can I fix it?
Reply
Report
Already a member? Sign in
+1
Report
4 de 5
http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-j...
Priya 1 week ago I need to create a chart. I am getting parameter from java . My java code public static List<CostSales> randomData() { List<CostSales> listOfCostSales = new ArrayList<CostSales>(); listOfCostSales.add(new CostSales(10.2,1)); listOfCostSales.add(new CostSales(20.2,2)); listOfCostSales.add(new CostSales(30.2,3)); listOfCostSales.add(new CostSales(40.2,4)); return listOfCostSales; } parameters.put("listOfCostSales", randomData()); jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,dataSource);
Then In Ireport I created a chart . In main dataset I created a parameter listOfCostSales as list and cost and month. And created a subdataset Chartdata with listOfCostSales, sale, month. In chart data Connection/DataSource Expression, I used Use connection expression from the drop down and set value new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{listOfCostSales}) Parameters Map Expression $P{REPORT_PARAMETERS_MAP} Parameters cost $P{cost} and month $P{month} I don't know what is wrong with my code. I can't access elements of list. I am getting null key .. For testing Printed month and cost by drag droping. I am getting null Please help me .I am struggling with this for last two week. Almost googled most of the sites and failed to find out the answer.
Reply
Report
Email
Not displayed publicly.
Website (optional)
If you have a website, link to it here.
Subscribe to
Submit Comment
Newer Post
Home
Older Post
5 de 5