Amazon festival offer

Wednesday, 24 April 2013

How to develop a bar chart in iReport ?

JasperReports supports a large number of built-in charts created using the popular open source library JFreeChart. Chart types include 2D & 3D Pie, 2D & 3D Bar, 2D & 3D Stacked Bar, Line, Area, Bubble, Gantt, Thermometer and Meter.
In this post, we will learn how to create a chart in iReport and will use “Sample Database (HSQLDB test)”.
We start creating a blank report based on the following SQL.
SELECT COUNT(*) orders,
             YEAR(ORDERDATE) year,
            MONTHNAME(ORDERDATE) month,
FROM orders
The query returns the amount of orders placed in each month in the several years. Open the query dialog, paste the query (be sure the JasperReports Sample db is the active connection) and read the fields from the query.
From the palette drag the chart element inside the title band and select the Bar 3D chart.
Step 1:- Select “Main report dataset” and press “Finish”.

Step 2:- Right click the chart and select Chart data. This will pop up the Chart data dialog.

Select the “Details” tab and add a new category.
Set as Series expression $F{YEAR}), as category expression the $F{MONTHYEAR} and as value expression the number of orders $F{ORDERS} as shown in the following figure.


Click “Preview” tab.
Just to change the property of graph because you may not able to see the month name in x-axis, to change the “Label Rotation” select the graph and go to property tab and change the “Label Rotation” to -50.



No comments: