You can build a report with Report Wizard of JReport Designer, and you can modify an existing report by dragging and dropping operations and changing the values of the object properties.
In this lesson, you will learn to create a simple report using Report Wizard.
JReport provides you with altogether twelve kinds of report templates which can simplify your editing work. You can choose the template you like in the initial Open Report dialog. Below is an example of a report with the title "Customer Sales Report" in left alignment format. Detailed customer records are grouped by Country and within each country by Region. The Sales from last year are totaled for each Region and for each Country.
Customer Sales Report
- Country: USA
- Region: CA
City Customer Name Phone Number Annual Sales Cupertino The Island Coffee (408) 777-0001 $98,239.00 >Irvine Cafe International (714) 243-9548 $51,958.00 Los Gatos International Coffee Hut (650) 867-9879 $81,349.00 Palo Alto Automatic Java Machines (650) 239-4690 $74,986.00 San Francisco Cafe San Francisco (415) 288-9090 $67,823.00 Annual Sales Totals: <>$374,355.00 Region: NY
City Customer Name Phone Number Annual Sales Dix Hill The Ultimate Bean (212) 938-4491 $54,738.00 New York Starmug Coffee (212) 834-9082 $101,001.00 New York Absolute Java (212) 946-3462 $50,600.00 Scarsdale The Java King (914) 657-9823 $78,321.00 Annual Sales Totals: $284,660.00
Annual Sales Total in the USA: $659,015.00 Building a report from a database is time consuming, but with JReport Designer, it only takes a matter of minutes to compile your data into a professional looking report.
- Start JReport Designer according to the instructions in lesson one.
- When the Open Report dialog appears, for this tutorial you should use the following catalog:
C:\jreport\Demo\Reports\Tutorial.cat
where c:\jreport is the path where you installed JReport Designer. You can use the Browse button to browse to the catalog file.- With the New tab active, click the Left Alignment icon to select it.
- Click the Create button to launch Report Wizard.
- With the first four tabs of Report Wizard, you will specify the source of data and select which ones to be displayed.
Data - Select the data source from all data objects to form a working set.
Joins - Join multiple tables in the default or the manual way.
Conditions - Specify the criteria which will retrieve data from the database to form the query of the report.
Display - Select which fields to show in the report.
Let's first look at the Data tab. Here you should select a data source from the Catalog Data Source drop-down list first, and then choose the objects you are interested in from the list below and place them into the Working Set list. For this example, we select the Default data source, and in the list below, expand the Connection item. Next, under the Tables node select the Customers table. Click thebutton to add all of the fields in the table to the working set. Or drag the fields to the Working Set directly. You can also expand the table and add individual field one by one to the working set.
By placing the objects in the working set, you have implicitly instructed JReport Designer to create a query, which will retrieve all of the data you will need for the report.- Skip the Joins tab, since the report we will create is a one-table report.
- Click on the Conditions tab. You can specify search conditions on this tab.
You can type your search criteria both in the format of Filter and QBE.
In the Filter format, a search condition expression will appear on the screen, which enables you to type your search criteria. The Expression includes not only the DBField selected, but also formulas and parameters. You can also manually type the strings supported by the database.
If you select the QBE (Query By Example) format, you will specify the search criteria in a template resembling the data record. All the data fields are shown to you, you just enter information that restricts the search to the specified criteria.
Here we want to compare the sales in California and New York. Therefore, in QBE, type the following conditions. Once finished, click the View SQL button to preview the SQL statement about your selection query so far.
Notes:
- In the QBE format, the column name may not show completely. For example, column name "Customers_Country" is cut off and shows only "Customers_Cou". To show the full column name, move the mouse cursor on the line between two columns, till the cursor becomes a double-headed arrow, you can move the line by dragging and dropping.
- You can adjust the order of the column. Move the mouse cursor on the column name, press the left button of the mouse, and drag the column to the place you want.
- Click on the Display tab.
Usually not all of the fields from a query need to be visible in a report. Therefore, you should indicate which fields to display by selecting the objects from the working set and adding them to the list on the right.
For this example, select: City, Customer Name, Phone, Fax and Annual Sales to display in the report.
Note: You can remove the selected field using buttonor change their order using buttons
or
on the top of the list.
- Click the Group tab.
Note: Records in a report are usually organized into groups based on certain criteria. With the Group/Sort tab you can enter the criteria to define multi-level groups. You can also specify the ordering of groups and ordering of records within each group.
We will group the data by selecting Country and then by Region. The arrows in the Direction column indicate the sorting sequence of the groups. You can choose from descending order (c,b,a), ascending order (a,b,c) or specify a special ordering criteria.
![]()
- Next you can sort records within the groups you created by clicking the Sort tab and selecting the sorting fields. Here choose the City field to sort the records, as shown below.
- Click the Summary tab to specify summary functions.
To generate a total sales amount for each Region group, select Annual Sales, clickto move it to the Summary Fields. The Function drop-down list allows you to select a summary function like sum, count, minimum, maximum, etc. We will select Sum for this example to see a total of Annual Sales. The Sum Function is computed when Break Field changes value at the end of a group. Clicking the Region field will cause a sum to be created for each Region group.
To generate a total sum of annual sales in the country, move Annual Sales to Source Fields again, select the Sum function for it. Leaving Break Fields empty, you can see Grandtotal in the Style column; JReport Designer will calculate the total annual sales.
![]()
- Click the Style tab to specify the page orientation.
- Click Finish to generate the report. The following is part of the report in the Design mode.
When the report Design window appears, you can make any adjustment you like to the report layout.
Report Inspector can be used to examine and change the objects in the report. Just highlight an object in Report Inspector to change the property of the object such as font, size, color, etc..
For more information, please refer to User's Guide | Refining the Report Layout | Report Inspector.
Another simple way to edit your report is through dragging, dropping, and clicking the Toolbar and the Menu bar. In the Design mode, first highlight the object you want to edit by clicking it. When the cursor becomes a cross, you can then move the highlighted object by dragging and dropping.
For this example, we have to manually move the column names from the PageHeader section to the second GroupHeader section, and move report title to the PageHeader section.
For more information about how to edit the report layout, please refer to User's Guide | Refining the Report Layout.
After the editing, your report in the Design mode may look like this:
- Click on the View tab to run your report and view it. What you are seeing is still a rough copy of your report.
- Final work on your report.
Now you are ready to fine-tune your report and give it a professional look. Remember, Report Wizard provides you with a quick start but JReport Designer provides a wealth of tools for you to adjust the report to your preference. Use Report Inspector to change font, size, position, and other variables. Do not forget that you can also move items anywhere in the Design view. Try to insert labels and texts and place objects in headers/footers and details.
Frequently you need to specify a parameter when running a report. For example, you may want to input an order date as an input parameter when running a report so that only orders on that date will be displayed. Typically, parameters are used as part of the query conditions (search criteria) so that only records satisfying that parameter will be retrieved to become part of the report.
- Select DBField from the Insert menu list, and then on the Insert DBField dialog select the Parameters tab, or on the Edit toolbar, click the Insert Parameter button directly.
- Click on the New button to create a new parameter.
- The next window should appear after clicking on the new button. The example parameter we created below allows the last person who edited the report to place his name on it.
In the Parameter Name text box, type in a name for your parameter. We chose " Editor" for this example. In the Prompting Text area, please enter a message that will appear. Our message was, "Please type in the name of the last person who edited."
Note: You can only create a one line statement.- The Value Type should be left as String. This allows the parameter to remain the same as text. There are also other Value Types.
Reference Notes: User Reference | JReport Objects | Parameter
Finally, place an example in the Default Prompt Value so that you have a format to follow. We chose "John Smith" since our parameter deals with name.- Click OK to finish.
- Select the new parameter and click the Insert button. Place it into your report.
- Click on the View tab to view your report.
- The following window will appear when you view the report.
You can type in any text field in the area. The default button will change the value back to its original value. In our case, that was John Smith.- This was the final outcome of our report.
Design:
View: