|
|||||||||||||||||||||
Adding a Report Title and DateSo now you can generate a report with real data. Next, add a title in the title bar. This title will be displayed only at the very start of the report. Suppose you want the title for this report to be "Employees/service", followed by the current date. To integrate the "Employees/Service" text, just place a static text zone in the title section (use "Edit/Insert Element/Static Text" or the "T" icon).
Now, suppose you want to display today's date as well. Insert a new text field ("Edit/Insert Element/Text Field"). Double-click on the text field object and go to the "TextField" tab in the window that just appeared (see Figure 8). Here you get a glimpse of the power of JasperReports. Because a compiled JasperReport is a Java class, you can use any Java expression to help build your report, as well as JasperReports fields, variables, and parameters. For instance, the "TextField" expression is a Java expression and will be interpreted as such.
To display the current date, you just create a new As a final touch, add a transparent border around the title ("Edit/Insert Element/Rounded Rectangle") and an image ("Edit/Insert Element/Image"), and then customize the colors and fonts (see Figure 9 for an example).
Calculating TotalsNow suppose you want to display the total cost of all employee salaries. To calculate values like this in JasperReports, you need to use report variables. You use report variables to store and calculate any temporary values you need in the report, such as totals, sub-totals, averages, and so on. Here are some important things you should know about report variables:
To display the report variables, open the "View/Report Variables" menu. You need to add a new variable to track employee salaries and calculate the total value. Let's call it total_salaries (see Figure 10). Set the variable class type to Double and the calculation type to Sum.
For now, you need to evaluate the 'emp_salary' field, so enter "$F{emp_salary}" as the variable expression. Now drag this variable into the Column Footer section, and add an appropriate text title (see the generated report in Figure 11). Using the same approach, you can easily add other types of variables: averages, counts, lowest and highest values, and so on.
|
|||||||||||||||||||||
|