JasperReports supports a large number of built-in charts created using the popular open source library JFreeChart. Chart types include Pie, Bar, Stacked Bar, Line, Area, Bubble, Gantt, Thermometer and Meter.
In this tutorial we will learn how to add a multi-series chart to a report. We start creating a blank report based on the following SQL query (we use the JasperReports Sample db):
select count(*) orders, year(ORDERDATE) year, MONTH(ORDERDATE) month from orders group by year(ORDERDATE), MONTH(ORDERDATE) order by year(ORDERDATE), MONTH(ORDERDATE)
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.
Right click the chart and select Chart data. This will pop up the Chart data dialog. Select the tab details and add a new category. Set as Series expression the field Year ($F{YEAR}), as category the Month and as value the number of orders as shown in the following figure.
Run your report. The following picture shows the final result.
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now