Report Example v5

Making Report example step by step.

 

Report creation

 

Open the Jaspersoft Studio to develop the report.

Once it is open we have to create a new report.

  • New → Jasper Report


 

Select the template "Blank A4" and click on "Next".

 

 

Modify the default name in the "File name" field with the name that we want to give to the jrxml file that we are generating.

Then select the folder in which we want to save it and click on "Next".

 

 

Next we have to select data adapter created previously (it's explained in the report documentation) upon which we have to make the query.

Here it is provided the option to insert the query but in this case we won't do it because we want to filter the report in a dinamic way using the created parameters so we avoid this step and click on "Finish".

 

 

Completed this steps an empty report is generated.

 

Parameters creation

On this step we have to create the parameters that we will use to filter the report.

To create those parameters right click over parameters in the "Outline" window → Create Parameter.

 

 

At the time that the parameter is created, it is automatically selected and its properties could be visualised on the "Properties" window like the next image shows.

By default the parameter is created with the name "Parameter1", which can be modified editing the "Name" field on the properties window.

By last we have to select the data type for the parameter:

  • Click on the button that is highlighted on the image below.

  • Is going to open the "Open Type" window which is going to be empty. To get acces to the data types we habe to search them on the "Enter the name prefix or pattern" field.

  • After filter the data type that we wnat to use, we have to select the one who saids java.sql (watch the example).


 

We are going to use 3 parameters to this report:

  • INITIAL_DATE (Timestamp)

  • FINAL_DATE (Timestamp)

  • CAMPANIA (String)

This parameters will be use to filter our report in a date range and a selected campaign.

 

Query insertion

After created all parameters we should insert the query.

On the "Outline" window rigth click over on the report → Datasets and Query...

 

 

 

The next image shows the query inserted by the user using the previously created parameters.

On this case the parameter CAMPANIA is written with quotation marks ('$P!{CAMPANIA}') to make that the reading of the query possible.

Once that the query was read (click on the "Read Fields" button) we have to remove the quotation marks because the parameter is going to recibe a list of values ('value1','value2','value3').

This applies to every parameter that are going to contain a list of values.

On this case we should do the next:

  •  campaign in ('$P!{CAMPANIA}')

  • click on "Read Fields" button

  • campaign in ($P!{CAMPANIA})

  • click OK

 

Fields y Text Fields

Once that all the fields has been read, are going to be showed on the "Outline" window on the "Fields" menu.

To use the fields that we want, just select them and drag and drop it to the "Detail" band like the next image shows.

 

 

Another way to use the fields that we get from the query is the next:

  • Select a Text Field from de "Palette" and drag and drop it into the detail band.


 

  • Double click over the Text Field (it open a window to select a field).

  • Select the field that we want and then click on "Finish".


 

The image below shows the fields after drag and drop them from de "Fields" menu.

Those fields adjust automatically to the Detail band's lenght and generate by default a static text element with the field's name, this is situated automatically on the "Column Header" band that is used to put the titles to the columns.

Static Text are used to put text into them, on this case we have to delete them because we will use Text Fields to internationalize the titles (it's explained farder in this document).

After that the fields were inserted into the report, we should adjust the bands size (red arrow) with the Text Fields width to make the report look better.

 

 

At the time that we have adjusted the bands and deleted the static texts generated automatically we proceed to add the text fields in blank to replace the deleted ones.

To generate a report that looks good we can add properties to the text fields to make them look better, some properties are:

  • Border

  • Color

  • Text alignment

  • Text size

The image below shows how to add borders to a Text Field.

Steps:

  • Select the Text Field. 

  • Into the "Properties" select "Borders" and then modify "Pen Width" field.

  • Also we can modify the color and the type of line that will have the  border of the text field.


 

The image below shows how to aling a text or an expression into a Text Field.

Steps:

  • Select a Text Field to apply this propertie.

  • Into the properties, select "Text Field" tab and then select the alignment that we want to use (Alignment).



The image below shows how to set the text size or the expression size into a text field.

Steps:

  • Select a Text Field to apply this propertie.

  • Into the properties, select "Text Field" and then select the font size (Font).


 

The image below shows how to give color to a text field.

Steps:

  • Select a Text Field to apply this propertie.

  • Into the properties, select "Appearance" and then select the color.

  • Uncheck the checkbox "Transparent". 


 

Internationalization

To internationalize the report we should put resources into the fields that we want to have in several languages for example titles or column names.

Before carry out the internacionalization we should create as many properties files as languages we want to use.

On this example we are going to use 2 languages (english and spanish) so we have to create one file named properties_en and another file named properties_es.

Those files ALWAYS must be located into the folder next to the report.

 

Steps:

  • We must have our properties files located next to the report in which we are going to use them.





  • Modify these files by adding the resources next to the description in the corresponding language as shown in the following image.





  • We must include the created resource into our text field expression editor with the following nomenclature.





  • At the time to execute our report, into our report properties, we should modify the field named "Resource Boundle" and make reference to the file which is going to be used.

  • To access to the properties, click over the report on the Outline window.






  • Go to the properties window and select the tab Report.

  • Click on the button 

      next to the Resource Boundle field.

  • Select the file that you want to use and then click "OK".



Add parameters to a report

 

Show the parameters that we use into the report is a good thing to do because allows the user to know about the filters that he is using.

Steps:

  • On the title band, add 2 fields per parameter (one field to stock the description and another to stock the parameter value).





  • Into the description Text Field we have to put the corresponding resource.

  • Into the Text Field which is going to stock the parameter value we have to puto the parameter name using the following nomenclature.

Add images to a report


To add an image into the report, make the following steps:

Into de palette section select, drag and drop the "Image" element into a band inside the report.

  1. Automatically open a window in which is listed a few options to upload our image. Our image is located into the same folder that is located our report and properties files so we select "Workspace resource" and click "OK".

  2. Select the image and click on the "OK" button.

    NOTE: Image format have to be png.

 

Result:

 

 

Add chart to a report

To add a chart into a report follow the next steps:

  • Into de "Palette" section select, drag and drop the "Chart" element into the "Summary" band.

  • At the time we drop the chart element it will open a window that shows several types of charts to include into the report like it shows on the following image.

  • Select "Bar3D Chart" chart and click on "Next".


 

Then the selected chart is showes next to their properties to modify.

 

 

  • We must add a field into the "Value" field and another field into "Category" clicking the button 

     next to the mentioned fields.

  • Then select the field acording to what we want to show on the chart.


 

The following step consist in adding a new value to "Series", this will be the description of our chart, then click on "OK" 

To complete this step click on "Finish".

 

 

Result final design:

 

 

To generate the report and visualize the final result with data follow the next steps:

  • Click on "Preview" tab.

  • Select the data base.

  • Complete the parameter fields to filter the report query.

  • Run.





 Final Result