Basic Report Creation

iReport/Jaspersoft Studio Support Announcement
As of version 5.5.0, Jaspersoft Studio will be the official design client for JasperReports. iReport will remain as a supported product in maintenance-only mode until December 31, 2015, meaning we will continue to fix critical defects in upcoming releases but no new features will be added to the iReport client. Continue to maintain your existing reports with the new Jaspersoft Studio!

This guide helps you to create your first report. It uses FoodMart data source, a MySQL database example provided when installing JasperReports Server.

Let's start

  1. Launch iReport. Click on File > Empty report.

    Figure 1

  1. Name your report and choose a path to store it.

    Figure 2

  2. Do Finish.

    Figure 3

Define Data Source

  1. Define FoodMart as your data source. See iReport - Adding a Data Source for a guide.

    Figure 4

Report Query

  1. Click on Edit Report Query icon.

    Figure 5

  2. Copy and paste the below SQL query in the Edit Report Query window.

    SELECT emp.employee_id, emp.first_name, emp.last_name, emp.position_title, emp.birth_date,
    emp.hire_date, emp.end_date, emp.salary, emp.gender, dep.department_id, dep.department_description
    FROM employee emp
    JOIN department dep ON (emp.department_id=dep.department_id)
    WHERE dep.department_id IN (1,2,3,4,5);

    Figure 6

    Note: if your query is valid, iReport will automatically retrieve the fields. If not, check your query mistakes.

  3. Then do OK to save your SQL query. You will see on your left the Report Inspector panel filled with query's fields.

    Figure 7

  4. For this example, keep the following bands: Page Header, Detail and Page Footer.
  5. To delete bands, right click on it and select Delete Band.

    Figure 8

Let's fill it out

Page Header Band

Palette Window

The Palette window contains different types of elements for a report.

  1. To activate Palette, click on Window > Palette.

    Figure 9

  2. Drag and drop 6 Static Text fields in Page Header band. Double click on each one and name them as below:

    Figure 10

Properties Window

Properties allow you to customize elements of a report.

  1. To activate Properties, click on Window > Properties.
  2. Select any static field and modify its properties: backcolor, text size, bold, italic, field size...

    Figure 11

    Note: some properties are directly available on that mini toolbar

    Figure 12

  3. Select all static fields, right-click and select Padding and Borders. Modify the Line witdh value to 1 and Line color to black. Then do OK.

    Figure 13

Formatting Tools Window

This is really important to use these tools. You can save a lot of time when creating reports !

  1. To activate Formatting Tools, click on Window > Formatting Tools.
  2. Select the following static fields: First Name, Last Name, Position Title, Salary, Department. In the Formatting Toolswindow, click on Align Top and Remove Horiz. Space.

    Figure 14

    See the difference, your fields are well organize with only 2 clicks.

    Figure 15

  3. Double click on the bottom border of Page Header band to reduce its height.

    Figure 16

    Now you know basic tools to create contents for your report.

Detail Band

  1. Drag from Report Inspector and drop in Detail band the following fields:

    first_name, last_name, position_title, salary, department_description.

  2. Double click on the bottom border of Detail band to reduce its height.

    FIgure 17

  1. Drag from Palette and drop in Page Footer band the 2 elements Current Date and Page X of Y.

    Figure 18

  2. For Current Date element, choose an appropriate pattern.

    Figure 19

  3. Place the 2 elements. Don't forget to stretch enough Current Date element to display the entire date. Double click on the bottom border of Page Footer band to reduce its height.

    Figure 20

Report Preview

  1. To preview your report, click on Preview button.

    Figure 21

  2. See the preview. Not bad but they are some issues:

    • Text touches cells' borders.
    • Salary display pattern is not clear.
    • Some department's descriptions are truncated

      Figure 22

Improving Display

  1. '''Text touches cells' borders:''' add some padding for all Detail band's elements: 5px for Left and Right; 2px for Top and Bottom.

    Figure 23

  2. Salary display pattern: see Salary field's Properties. Add the following Pattern:

    $ ###,###,##0.00

    Figure 24

  3. Truncated column: select all Detail band's elements and go to Properties. Set Stretch Type to Relative to Band Height. Check Stretch With Overflow box.

    Figure 25

  4. Click on Detail band and go to Properties. Uncheck Split allowed box. This will prevent from row splitting between 2 pages.

    Figure 26

  5. See the preview. Your report looks better now.

    Figure 27

See also...