Jasper Reports Example

Jasper Reports example – Create Pie chart using iReport

In this blog I will show a jasper reports example using iRport designer. In this post I will show how to create a pie chart.  This is a very simple jasper reports example. I have one table called category and it has different categoryno with category name. Each category has subcategory. I want to show how many categories are there by pie chart.  Category table structure link will give you the table structure and some sample data. I used MySql database for this report. It supports couple of databases.

Jasper Reports example

The JasperReports api is the most popular open source reporting engine. It can be used in java enabled applications, including J2EE or web application to producing dynamic content. It is a Java based project. It reads its instructions from an XML or .jasper file. The tool iReport is use to create report template, design of report,  setting value of parameter and query etc. In this Jasper reports example  we will feed data from any kind of data sources.  It produce different kind of report like HTML, PDF, EXCEL, XML etc. To integrate a j2ee application, you need to add jar file to class path.  JasperReports reports are defined in an XML file format. This XML file is called JRXML file. So its file extension is .jrxml.  This file is readable, any one can easily modify it. iReport designer tool generates this jrxml file. We can create sub-report using iReport tool. In master details report we need sub-report. iReport is a graphical representation of jrxml. It is very useful tool for designing the entire report. After compiling a jrxml file iReport produces a file is called jasper file. Its extension is .jasper. A jasper file is used at runtime to produce reports.

If we need format any data we can add additional java code to report using iRerport. It supports all java codes. It is another beauty of iReport. For example currency, date format we can use it. Even column can show/hide based on value. That means we can add if / else logic. iReport designer runs reports using all data sources and also apply all internal java logics.

I have showed other jasper reports example in my other post.

Jasper Reports example – Steps for iReport designer

To get more details on Jasper reports example and documents click here and iReport is available at here.

  • Create New document from iReport. use this band value title = 30, columnHeader = 15, detail = 15 and summary = 300 and others = 0.
  • Add Query:     select category “Cat No”, subcat_name “category Name”, count(category) total from category
    group by category order by 1
  • Add 3 fields – Cat No, Category Name, Total to Detail band.    Jasper Reports Example - detail-band
  • Click the char button and select the Pie 3D. I put its width is 268 and height is 203.   Jasper Reports Example - ui2
  • right click on chart and select cart properties. select cart data tab, select the Details tab. and put the value as follows –  for Key Expression = $F{category Name} ,  Value Expression = $F{total},  Label Expression = $F{category Name}
  • click close.
  • b4 execute you must select your database connection. now click Execute with data connection. the output file will looks like as follows

jasper reports example: output-pie-report

4 thoughts on “Jasper Reports Example

  1. Hi.

    Your post is quiet usefull for newbie..However, there is no java code for display chart in pdf file.

    Do you know how? and could you send to me guide/tutorial if you know?

  2. hi,

    Im sorry to bother you, if you mind, I had a question for you about that topic. First of all, I m using the netbeans IDE 6.7 with ireport 3.5.2 plug in and the oracle to take datas. Here is my problem I couldn’t understand the (right click on chart and select cart properties. select cart data tab, select the Details tab. and put the value as follows – for Key Expression = $F{category Name} , Value Expression = $F{total}, Label Expression = $F{category Name}) part when I clicked on the right button there is chart data and in it there are two choices details and datasets how could I fill in the blanks, there is nothing into details, I mean the concept of the graph first I had to write sum of the numbers and seperate them into the groups can someone explain me that, if you mind to help me, I would really appreciate it.

Leave a Reply

Your email address will not be published. Required fields are marked *