The following sections provide details on creating views with the Ad Hoc Editor:
• | Summaries |
• | Setting the Data Format |
• | Custom Fields |
Summaries
Summaries show the result of a function applied to all data values.
• | In Ad Hoc table views, each field can display a single summary calculation. You can add a summary to a column by right-clicking it and selecting Add Summary from the context menu. The summary function is automatically applied to all groups in the table. Summaries appear at the bottom of each group, as well as at the bottom of the view. When a new group is added, it includes a summary for each column. |
• | In crosstabs, each measure displays a summarized value. Summaries determine the values of the measures at the intersection of each row and column. |
• | In charts, the type of chart determines whether measures are summarized. If summaries are used, they determine the size or location of the graphical elements that represent your data. |
In general, you can change the summary function of any measure, with the exception of those that use the percent of total and percent of parent custom field functions.
By default, JasperReports Server summarizes fields of each datatype as follows:
Datatype | Summary Function | Description |
Numeric | Sum | Displays the sum of all values in the set. |
Date | Count | Displays the total number of values in the set. |
String | Count | Displays the number of values in the set. |
Boolean | Count | Displays the number of values in the set. |
Select from the following options to set a measure’s summary function in any type of view:
Option | Meaning | Available for…. |
Average | Displays the average of all values in the set. | Numeric |
Count All | Displays the number of rows in the set. | Boolean, Date, Numeric, and String |
Distinct Count | Displays the number of unique values in the set. | Boolean, Date, Numeric, and String |
Maximum | Displays the highest value in the set. | Numeric |
Minimum | Displays the lowest value in the set. | Numeric |
Sum | Displays the grand total for the set. | Numeric |
For Table and Crosstab views, you can remove summaries:
• | For tables, remove a column’s summary by right-clicking the column or the summary itself, and selecting Remove Summary from the context menu. |
• | For crosstabs, remove a column group’s summary by right-clicking the group label and selecting Delete Column Summary; remove a row group’s summary by clicking Delete Row Summary from the same context menu. These options are only available for the outermost group on either axis. |
Setting the Data Format
You can set the format of data in tables and crosstabs. Click a row or column header and select Change Data Format from the context menu. In tables, the format is applied to all rows as well as the group- and view-level summaries. In crosstabs, the format is applied to the measures.
The options that appear in the menu are the formats available for objects of the given datatype. For example, for monetary datatypes, the menu might list $1,234.56, -$1,234.56 and ($1,234.56), while for date datatypes it might list December 31, 2008, and 12/31/2008. By default, non-integer fields use the -1,234.56 data format; integers use -1234.
In some cases, the options in the Change Data Format menu are affected by the locale; for example:
U.S. English | French |
U.S. English and French Versions of a Context Menu |
Custom Fields
You can always create custom numeric fields in the editor, such as multiplying a field by an absolute number, subtracting one field from another, or displaying a field as a percent of a total for a column or group. You can add the fields to the view as you would any other numeric field.
Dialogs for Creating Custom Fields | ||
Single-Field Operations | Two-Field Operations | Two-Date Operations |
Selecting the fields | Right-click any numeric field in the list of available fields and select Create Custom Field... To work with multiple fields, use Ctrl-right-click on the second field. In tables, you can also create custom fields by right-clicking columns in the canvas. |
Single-field arithmetic | In the dialog for single fields, enter a constant operand for one of the arithmetic operations and click Create Field. When subtracting, and dividing, the order is of the operands is significant. Click Swap if necessary to achieve the result you want. |
Special function on a single field | In the dialog for single fields, select one of the advanced functions and click Create Field. |
Two-field arithmetic | Click the first field, Ctrl-right-click the second field, and select Create Custom Field... from the context menu. Select an operation to perform on the fields and click Create Field. When adding or multiplying, the order in which you select fields doesn’t matter. When subtracting and dividing, the order is significant. Click Swap if necessary. |
The only operation available for date fields is to compare the difference between two dates. Select two date fields, right-click and select Create Custom Field... In the Custom Field dialog, select the units in which to express the time difference, such as Minutes, Hours, or Days. You may also set the data format on the custom field to show decimals or round to the nearest integer. | |
Editing a custom field | Right-click the field and select Edit Formula from the context menu. In the Custom Field dialog, make the edit and click Update Field. |
As with any field, you can add a summary, change the data format, or change the display label of a custom field. You can also use custom fields in other custom fields to create more complex computed values.
Recommended Comments
There are no comments to display.