Understanding Measures. Jaspersoft iReport
Reklama
Reklama
iReport Ultimate Guide
16.2.2
Understanding Measures
A measure is an object similar to a variable. It is always, in some way, the result of a calculation performed on a value for each row and column group that intersect a cell. Expressions for elements in a crosstab, such as print-when expressions and textfield expressions, can only contain measures. In this context, you cannot use fields, variables, or parameters directly; you always have to use a measure.
To create a measure, right-click the measures node in the outline view and select
Add Measure
(see
adds the new measure to the outline view.
Figure 16-14 Adding a measure
Just as when you create a new group, you’ll need to define an expression for the measure. The easiest way to display a new measure is to use a textfield. Drag a textfield element into a cell and set the proper textfield expression (for example, with a measure name like
$V{Average_freight}
) and the proper expression class for the textfield, which must be consistent with the measure type.
There are several options you can use to set a measure. Besides the name, class, and expression, you can set the calculation type. If the available calculation types are not enough, you can provide a custom
Incrementer
class by means of a Factory that returns an instance of that class (the factory must implement the interface net.sf.jasperreports.engine.fil.JRIncrementerFactory
).
Figure 16-15 Measure Properties
If you want to display your measure as a percentage of the grand total, you can set the property
Percentage of type to
Grand Total
.
Finally, you can specify a custom calculator class to perform the percentage calculation (the class must use the interface net.sf.jasperreports.crosstabs.fill.JRPercentageCalculator
).
16.3
Modifying Crosstab Element Properties
To see the crosstab properties in the property sheet, select the crosstab node in the outline view (see
310
Pobierz
Reklama