Creating and Designing Report Using iReport - Part 1
page 4 of 6
by Anuva Das
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 58003/ 836

Designing Report

To design JasperReports report, select “File -> New Document” from the menu. Enter the report name in the “Report name” field and click on the “OK” button to open a blank report design.

Adding Static Text

To add  Static text to the report, click on the "T" icon at the top of the screen or select “Edit ->Insert Element -> Static Text” from menu and  place it where you want to display the text.

Figure 6

Adding Report Query

To retrieve data from the datasources select “Data-> Report query” from the menu to open the Report query dialog. Make sure that “Automatically Retrieve Fields” checkbox is checked. Now write your SQL query in the textbox. Click the “OK” button to close the dialog.

Figure 7

Adding Text Fields

Report fields are used to display data retrieved from the datasources into the report. All the fields must have the same name and type as the columns they map .To add fields to the report click on the "F" icon at the top of the screen or select “Edit ->Insert Element-> Text Field” from the menu and place it where you want to display the field. Or simply drag and drop them from Fields onto the section of the report where you want.

Figure 8

 

Adding Images

To add an image to the report, select "Edit->Insert Element->Image" from the menu. Go to the properties of image field and click the “Image” tab. Give the path for the image by clicking on the “Find” button.

Figure 9

Adding Parameters

Parameters are used to dynamically modify SQL Query. To add a parameter to the report select “View -> Parameters” from the menu, then Click on the “New” tab. In the “Add/modify parameter” dialog enter/select the following values and click the “OK” button afterwards.

·         Enter the Parameter Name (e.g. City).

·         Select theParameter class type (e.g. java.lang.String).

·         Make “Is for prompting” checkbox checked so that when you run the report from iReport it will prompt you to enter the value for that parameter.

·         Enter the Default value expression (e.g. “Bombay”).

Figure 10

Adding variables

A report variable is used to perform various calculations on the corresponding expressions. Here are some important things that you should follow when designing the report using variables.

·         The variable class type must be matched with class type of the field on which it will perform calculation.

·         The calculation type tells JasperReports what to do.

·         The variable expression represents the value to be evaluated in the calculation. It may be Fields, Variables, Parameters, wizards, recent expressions, etc.

·         As a variable can reference other variables, so the referenced variables must be defined previously in the report design. So the order of declaring variables is important in report design.

To add the report variables, select "View->Variables" from menu and click on the “New” button. In the “Add/modify variable” dialog enter/select the following and click the “OK” button afterwards (see figure 11).

·         Enter the Variable Name (total).

·         Select the Variable Class Type (java.lang.BigDecimal).

·         Select the Calculation Type (Sum).

·         Select the Variable Expression ($F{QTY_SALES).

Figure 11

Now drag and drop this variable into the columnFooter, lastPageFooter or Summary section to display result.

Adding Groups

Groups in a report define a collection of related records. A report can contain more than one group and a group can contain another group, so the order of declaring a group in a report design is important.

Suppose you want to create a report that will group salesman by state and calculate total number of item sold by each group. For that, first define a report group by selecting "View/Report Groups" menu and then click the “New” button. In the “Add/modify group” dialog Enter Group name and Group Expression, then  click the “OK” button.

Figure 12

To create a report using the group you must write the SQL query properly ("order by state"). When you add a new group, you will see two new sections at the top and bottom of detail section. In this example it is called "stateNameHeader" and "stateNameFooter." Suppose you want to display the total number of items sold at the end of each group. For this create a variable ($V{totalQty}) and make the “Reset type” as a group, then drag the variable into the "stateNameFooter" section. The generated report looks like the following figure.

Figure 13

 

 

Adding Charts

Using iReport you can design reports with charts. JasperReports currently supports the following types of charts: Pie, Pie 3D, Bar, Bar 3D, XY Bar, Stacked Bar, Stacked Bar 3D, Line, XY Line, Area, YX Area, Scatter, Bubble, Time series, High Low, Candlestick, meter, thermometer, and MultiAxis. Chart parameters are different for each type of chart.

Suppose you want to add a pie chart that shows the total number of items sold by each salesperson at the end. For that, first add a new chart in the summary section using the "Edit->Insert Element->Chart" menu. Choose a chart. Open the properties by right clicking on the chart then go to the “Chart” tab.  Click on the “Edit Chart Properties” button and go to the “Chart data  -> Details.” In the Chart properties dialog enter the three expression as shown in the following figure and click the “Close” button afterwards.

Figure 14

Now the user has to make the desired visual settings for it. When you run the report, you will get a pie chart at the end of your report as shown in the following figure.

Figure 15


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 4 and 3 and type the answer here:

User Comments

Title: subreport   
Name: nathan
Date: 12/31/2008 2:27:30 AM
Comment:
hai couldnot load object from location when subreport creation if anyone have know please tellme
kolanchinathan.e@gmail.com
Title: creating hyperlink to report to view another report   
Name: versam
Date: 11/28/2008 5:40:00 AM
Comment:
Hi, I'm new to jasperReports. I have created a report and and want to create a link to that report to view another one and be able to view it in HTML viewer
Title: Bar Chart   
Name: Bill
Date: 10/16/2008 4:30:33 PM
Comment:
Hi I was able to get the pie chart working
But for some reason the bar chart is not working, can someone please help me out.

Thanks,
Title: error in installing ireport Exe   
Name: Prabha
Date: 10/7/2008 4:28:25 AM
Comment:
Getting Error while running iReport saying error while loading configuration file
Title: error in installing ireport Exe   
Name: Prabha
Date: 10/7/2008 4:08:12 AM
Comment:
\
Title: error in installing irport Exe   
Name: Prabha
Date: 10/7/2008 4:07:26 AM
Comment:
\
\
\
\
Title: ireport   
Name: bala
Date: 9/8/2008 7:43:19 AM
Comment:
i am using one main report and one sub report, the main report field value is passed to sub report as parameter, the sub report query is where acctvalue=$p{acctvalue},that the query window will dispayed please set a the default value parameter acct value, please give me the solution
Title: Sum of Variables   
Name: viji
Date: 9/1/2008 1:40:05 AM
Comment:
Hi,
I am using iReport 3.0.0.Now my problem is sum of fieldtype(duration).The data type of field is String.The sum calculation is stored into integer variable(Total number of duration).The error is cannot cast String into int.Please anybody give me the solution.
Title: ireport problem   
Name: emine
Date: 8/19/2008 4:24:25 AM
Comment:
hello..
i am working at ireport 2.0.4 and showing depend to condition(example show or dont show) that my fields come from my database.then when i execute, dont want to see fields's location are blank.how can i solve this problem?
Title: ireport in jsp   
Name: lia
Date: 8/15/2008 2:27:20 AM
Comment:
how to run ireport from jsp..??

kaliana1@yahoo.com
Title: problem with sub-report   
Name: su123
Date: 8/14/2008 9:28:42 AM
Comment:
Hi,
I'm trying to include a sub report within a report. The sub report by itself works perfectly fine. But when i include it in the main report it is not filled with data. I'm using a ORACLE connection. There are no parameters in the sub report. When executed the main report display 'The document has no pages'
Title: how to download and install jasper report 2.0.2 and iReport 2.0.2   
Name: viji
Date: 7/26/2008 1:45:15 AM
Comment:
Please send the required url of downloading jasper 2.0.2 and iReport 2.0.2 and give the steps of installation.
Title: how to call jasperreport from jsp   
Name: meera
Date: 7/2/2008 1:10:05 AM
Comment:
could you please send me a sample code of how to call it from jsp..so it will be very helpful for me...
my email id is testmail_99@yahoo.com
Title: Student SE   
Name: Shirhan
Date: 5/28/2008 9:22:03 AM
Comment:
I am stuck at the parameter thing... by reading this I got the idea. Thank you very much.

Keep up the good work!!

:-)
Title: how to call ireport from jsp   
Name: dhanya
Date: 5/21/2008 5:18:17 PM
Comment:
hi,
i read your article for ireports..and i installed ireport in my system..i made sample reports .but i dont know how to connect it to jsp.in the article its written that a classpath need to be set..how is it?could you please send me a sample code of how to call it from jsp..so t will will be very helpful for me...my id is dhanya.shibu@gmail.com.thanks in advance
Title: help   
Name: Jay
Date: 4/15/2008 5:12:25 AM
Comment:
Hey Im having a problem making an image a background of a field.. I made the field transparent and I sent the image to the back but still the field overshadows the image... How can I make the field transparent so the image can appear behind it..
Title: Hi   
Name: Rajashekharayya
Date: 3/17/2008 3:22:25 AM
Comment:
Hi
Thank You for having discussion of iReport,i am getting a problem during chart export into excel.but i am able to get for pdf in excel image is not printing
Title: Ireport set preset size   
Name: hyank
Date: 3/1/2008 5:53:54 AM
Comment:
Hello there
im newbie in ireport, i have a problem in set preset size manual outside ireport. i want user can choose the paper size when the report is printed. but i don't know the way??
can you help me??

thanks before
Title: Reports(To Himanshu....the question copier!)   
Name: Harilal
Date: 2/20/2008 11:53:07 AM
Comment:
Title: Feedback and facing problem
Name: Himanshu Jain
Date: 2/8/2008 6:07:32 AM
Comment:
This is really useful aricle for beginners and intermediate users.
Could anyuone help me out.

Now I face new problem related with the Bar Charts. In my project I commonly use Japer Reports to generate Report (with the help of i-report2.0). Now I need to represent some of the data’s in a chronological way. And for that purpose I select the Bar chart.
I have two values "Actual Data" And "Predicted Data", And I need to contrast these two values in My bar chart. But in i-Report I found only one option to set the values for the Bar Chart. In X-axis the object name and in Y-axis I set the Numbers. And I want to represent the Bar chart as the First bar repesent the predicted data and the neighbor bar represent the actual data...........
If any one has an idea or solution to this problem kindly give here
Thanks and Regadrs
Himanshu

First of all I am(Harilal.A.S.)very thankfull to Mr(?)"Himanshu" to ask this question why because this article is just I asked in the Java-Ranch forum....and i see that you copy the entire thing (that I asked in java ranch forum) and paste here......anyway if you got any answer post it in Java-Ranch Forums....as my anwer...........(and these type of copy the contents is not a right method....)
Title: Software Engineer   
Name: Abhishek
Date: 2/18/2008 10:53:56 AM
Comment:
Hi,

How are you?

I'm trying to export jasper report into pdf. But when I do that I get 25 pages with the same content.
I just need only once.

I'm using the subreport inside a master report.
I've two groups created.

So, can you please let me know how to take care of this?'
And, also can you please let me know how to reduce the white spaces between the columns and rows in the subreports?

Thanks in advance.
Title: Feedback and facing problem   
Name: Himanshu Jain
Date: 2/8/2008 6:07:32 AM
Comment:
This is really useful aricle for beginners and intermediate users.
Could anyuone help me out.

Now I face new problem related with the Bar Charts. In my project I commonly use Japer Reports to generate Report (with the help of i-report2.0). Now I need to represent some of the data’s in a chronological way. And for that purpose I select the Bar chart.
I have two values "Actual Data" And "Predicted Data", And I need to contrast these two values in My bar chart. But in i-Report I found only one option to set the values for the Bar Chart. In X-axis the object name and in Y-axis I set the Numbers. And I want to represent the Bar chart as the First bar repesent the predicted data and the neighbor bar represent the actual data...........
If any one has an idea or solution to this problem kindly give here
Thanks and Regadrs
Himanshu
Title: Date Display   
Name: Prabha
Date: 12/10/2007 1:09:52 AM
Comment:
Hi All,

I need to display the date in the final report. I am using xml datasource. In the field class type i have chosed java.util.Date. In the pattern iam choosing dd/MM/yyyy. In the xml file i have the value as 10/05/2007. But I am getting the error when executing the report.Can anyone help?

Error filling print... null
org.apache.commons.beanutils.ConversionException at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java :231) at org.apache.commons.beanutils.locale.LocaleConvertUtilsBean.convert(LocaleConvertUtilsBea n.java:249) at net.sf.jasperreports.engine.data.JRXmlDataSource.getFieldValue(JRXmlDataSource.java:342) at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:815) at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:779) at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1105) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:111) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:763) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:688) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:960) at java.lang.Thread.run(Thread.java:595) Caused by: java.lang.NullPointerException at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:584) at java.text.SimpleDateFormat.applyPattern(SimpleDateFormat.java:1766) at net.sf.jasperreports.engine.util.JRDateLocaleConverter.parse(JRDateLocaleConverter.java: 83) at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java :225) ..
Title: Print 2 reports, in same pdf   
Name: Alberto Rosales
Date: 12/6/2007 11:56:13 AM
Comment:
hi,I need some helppppppp, I have created 2 reports from a java swing application, but now I have to print both reports in the same pdf File, how can I do it???
Title: chart   
Name: boikanyo
Date: 11/5/2007 9:25:14 AM
Comment:
thanks very much to Anuva......
i'm now able to walk through some things in ireports n jasper reports.........

thanks again bra...
Title: Jsp report   
Name: mudita
Date: 10/31/2007 1:28:40 AM
Comment:
hi all ,
i want to knw how i can create report in JSp..i m new ..so can nyone help me..
Title: nothing useful   
Name: Balaji
Date: 10/8/2007 9:25:20 AM
Comment:
Nothing is useful in this article
Title: Error   
Name: Gisela
Date: 10/1/2007 3:29:46 PM
Comment:
Hi!
How to use a java servlet page for the user to add a comment and reply to a comment.Could you please send me the sample code to my email address.
Thank you
Title: doubts regrading compliation and jsp page   
Name: Shailly
Date: 9/29/2007 3:54:20 AM
Comment:
Hi I am new to Jasper.
While compliing it , I am getting MAIN CONSOLE error as:
error loading configuration file.
plz tell me the way out.

how to use it in jsp page?

plz help with sample code.

my id: shailly@techmahindra.com
Title: Link from pdf to jsp page   
Name: priya
Date: 9/24/2007 3:06:56 AM
Comment:
Hi,

Is it possible to give link from a pdf report created to a jsp page , where I can pass the parameters of name=value pair type from pdf to jsp page
Title: Very Easy to Understand   
Name: Revathi
Date: 9/3/2007 8:00:08 AM
Comment:
Hi Anuva

This is first article which made me understand how iReport works. I am still exploring for new features amd also awaiting your nest Part I - Advanced Features.

Thanks
Title: ireport questions   
Name: mmus
Date: 8/23/2007 2:15:17 AM
Comment:
hi ! i`m the newbie in using ireport.. can u tell me where is the location of the jrxml file when u execute a report using i report?..

one more thing ..i also need sample code how to call this jrxml from jsp form through servlet?.. this is my email
hentamsaja82@yahoo.com

thanks in advanced
Title: reply to Sathesh kumar   
Name: Anuva
Date: 8/10/2007 5:45:54 AM
Comment:
create a JRXML or XML file using iReport.call this from servlet or jsp(which i already discussed in my article "creating report JasperReport") and then call this servlet or jsp in ur program.If u ve any doubt send ur mailling addres,so that i can send u a sample code.
Title: iReport in Eclipse   
Name: Sathesh kumar
Date: 8/10/2007 5:00:16 AM
Comment:
Is it possible to open the iReport in eclipse IDE?
Title: iReport Creation   
Name: Sathesh kumar
Date: 8/10/2007 4:47:04 AM
Comment:
This article is very useful for who are new in Bussiness Intelegence domain.
If you provide the details about how to call this report in server side program, It will very helpfull.
Title: ..   
Name: Peter
Date: 8/7/2007 3:54:50 AM
Comment:
Good article, just a pity, its not more extensive. But at least i started to understand little bit the things about iReport. Article recomended in sourceforge is piece of shit
Title: hyperlink on ireports   
Name: boikanyo
Date: 6/6/2007 7:04:58 AM
Comment:
hi.is it possible to have a tutorial on how to add hyperlinks on ireports.link that will maybe open a .doc or pdf or maybe some page.......

thanks
Title: thanks to anuva   
Name: boikanyo
Date: 5/25/2007 5:44:06 AM
Comment:
thank u very much,i had the same code but it worked out of a sudden after adding this other library.but hey ur help is much appriciated.
i convinced my boss dat jasper is de way so,my head is on the block im always looking 4 solutions and im new on this jasper thing so pls be patient when i ask lot of questions.
Title: Reply for boikanyo   
Name: Anuva
Date: 5/22/2007 2:23:19 AM
Comment:
Thanks.u can use above chart method to design ur chart,save it as .JRXML file.then use the following servlet code to create chart.

****************************************
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.export.*;

public class chart extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
ServletOutputStream servletOutputStream = response.getOutputStream();
Connection conn = null;
JasperReport jasperReport;
JasperPrint jasperPrint;
JasperDesign jasperDesign;
try
{
// get a database connection
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.10.85:1521:oracledb","demo","demo");

// load JasperDesign from XML and compile it into JasperReport
jasperDesign = JRXmlLoader.load("C:/report/ireportChart.jrxml");
jasperReport = JasperCompileManager.compileReport(jasperDesign);

// fill JasperPrint using fillReport() method
jasperPrint = JasperFillManager.fillReport(jasperReport,null,conn);

JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/report/chart.pdf");
response.setContentType("application/pdf");

JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
servletOutputStream.flush();
servletOutputStream.close();
}
catch(SQLException sqle)
{
System.err.println(sqle.getMessage());
}
catch (ClassNotFoundException e)
{
System.err.println("No
Title: pdf   
Name: boikanyo
Date: 5/21/2007 7:24:28 AM
Comment:
ok.i realy apreciate this article as i learned much from it but i realy would apreciate it when it had a code to display it on a browser(including a chart) using pdf

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 1/6/2009 11:57:36 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search