FCI-Helwan blog

Just another FCI-H weblog

Java Reporting – Part 4

Today’s article is the last one in the java reporting series. Through parts 1, 2, and 3 we have discovered JasperReports architecture, declarative file construction, integration with live parameters, and finally working with iReport as designing tool. Those topics are only the basic introduction to java reporting world and this series is not meant to cover the whole features of JasperReports, you can consider it as the kick start in the reporting field where every new report is supposed to contain new cases that formalize your experience.

There was a time when charts’ reports were considered as one of the imaginary features that clients have dreamt with for a long nights, but they also were suffering from usual nightmares when dream reach to the payment point, that is a result of a quote says “When development is hard; the customer should pay for that too”. Thanks to open-source community that age went and will not come back again, today as a result of cumulative work in open charts’ libraries and engines we became able to build a graphical chart reports in a smooth and easy way without the usual headache of plotting and rendering the results, which is also –unfortunately- rescued the customer financial plans from the definite fate.

In toady’s article we are going to create a Line chart report as sample application of chart reports with JasperReport and iReport. Actually there are a lot of graphs you can work with through jasperReports, e.g. Pie, 3D Pie, Bar, 3D Bar, XY Bar, XY Line, XY Area, Time Series, Multi-axis, Meter, etc. I chose Line chart report for our sample as it is a good example to cover 3-variables graphs.

As we mentioned before, most of reporting tools depend mainly on the chart engines and frameworks for plotting and rendering the resulted graphs, our tool -JasperReports- depends on a very popular, powerful and flexible open source charting library called JFreeChart.
So to get ready you need to download JFreeChart Library from here:
http://www.jfree.org/jfreechart/download.html ,
Extract the compressed file and add these libraries to your project classpath:
jfreechart-1.0.xx.jar (jfreechart-1.0.10.jar)
jcommon-1.0.xx.jar (jcommon-1.0.13.jar)

Report Definition
Database architecture:


Report Result: report should draw a graph line -for each item- that represents the total amount (on the y-axis) of in-operations divided by the days (on the x-axis).
Report Query:
[SELECT item.ITEM_NAME, to_date(OPERATION_DATE,’dd-mm-yyyy’) operationdate, SUM (stock.AMOUNT) amount
WHERE stock.ITEM_ID = item.ITEM_ID and stock.OPERATION_TYPE =1
GROUP BY item.ITEM_NAME, to_date(OPERATION_DATE,’dd-mm-yyyy’)
ORDER BY operationdate , item.ITEM_DATE ]

The above query will retrieve the graph result for all items in the stock; we can narrow it down by adding date period condition or specify item id in run-time search criteria as declared previously in part 3.

1- Open iReport.
2- From the toolbox choose ChartTool and draw your graph control in on of the bands that don’t get repeated in the same page (background, pageHeader, ColumnHeader).
3- From the pop-up window choose your chart type (Line Chart) as shown in the image below.

4- Add the report query from Data -> Report query
5- Open Chart Properties (Right-click your chart and choose Chart Properties) and open Chart Data tab, then open the inside tab called Details and press the Add button, as shown:
6- The Expressions in the shown dialog are:
-Series Expression: represents the graph lines.
-Category Expression: represents X-axis values.
-Value Expression: represents Y-axis values.

7- Axis labels, lines colors, delimiters shapes, legends and other graph properties can be handled from the Chart properties dialog.

Now execute the report in JRViewer and watch the results:

That’s all, you’r report is ready to get linked with application and exported to whatever format you want without any modification in your code –except the jrxml file name-.

Here we reach to the end of this series, it didn’t cover everything in reporting field but I wish it could help as introduction for beginners and for those need kick start.

Thanks and best regards,
Hossam Sadik

For detailed topics about JasperReports please refer to these books:
The Definitive Guide to JasperReports by Teodor Danciu and Lucian Chirita
JasperReports for Java Developers by David R. Heffelfinger


June 23, 2008 - Posted by | JAVA


  1. Very nice article. Thanks 🙂

    Comment by Anonymous | July 17, 2008 | Reply

  2. The first wow gold thing for wow gold you to consider buy wow gold about the buy wow gold Druid class cheap wow gold is this: Is the cheap wow gold Druid class wow power leveling right for wow power leveling you? The power leveling Druid class power leveling is kind of wow gold unique in that buy wow gold it’s not for cheap wow gold everyone. While world of warcraft gold master of none.

    Comment by wow gold | February 16, 2009 | Reply

  3. I like play online game, I also Buy metin2 gold and Metin2 gold, the Metin2 yang is very cheap, and use the Cheap metin2 yang can buy many things, I like Cheap metin2 gold, thanks, it is very good.

    I like play online game, I also Buy Perfect World Gold and Perfect World Gold, the Perfect World Silver is very cheap, and use the Perfect World money can buy many things, I like cheap Perfect World Gold, thanks, it is very good.

    Comment by Anonymous | April 14, 2009 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: