Using the ViewFormat Object to Format Numbers

The ViewFormat object is a collection of properties that a data view uses to format the numbers that it displays. Each of the Dataview components that can have distinct number formats has methods for specifying its ViewFormat. For graph tick labels, the ViewFormat of the associated axis determines the format of the numbers in the tick labels. The graph MarkerText component can have five different ViewFormat objects, one for each of the different situations of the marker text.

The ViewFormat object is in the oracle.dss.dataView.managers package.

Objects that have ViewFormat objects have the methods getViewFormat and setViewFormat. Most of these objects implement the Formattable interface, which is defined in oracle.dss.dataView.managers. Because the setViewFormat and getViewFormat methods of the graph MarkerText component have arguments to specify the circumstance in which a ViewFormat is to be used, the MarkerText object does not implement Formattable.

ViewFormat properties and default values

The following table lists the number formatting properties in the ViewFormat object, with their descriptions and default values.

Property

Description

Default

NumberType

Whether the value is currency or not (general number);Note: In graphs, NUMTYPE_PERCENT is not useful. Graph number formatting automatically understands that numbers are percentages when you use a percent-type graph, such as a pie graph or a percent line graph.

general number

CurrencySymbol

Symbol used to identify currency

$

NegCurFmt

Format for displaying negative currency values

($1)

PosCurFmt

Format for displaying positive currency values

$1

NegNumFmt

Format for displaying negative number values

(1)

PosNumFmt

Format for displaying positive number values

1

DecimalSeparator

Symbol that separates the integer part of a number from the fractional part

taken from the locale

ThousandSeparator

Symbol that separates thousands from hundreds

taken from the locale

DecimalDigit

Number of digits in the fractional part of a number (the part to the right of the decimal separator)

taken from the locale

LeadingZero

Whether values between 1 and -1 have a zero in the integer part of the number

true

ScaleFactor

How much to abbreviate the number

full number (no scaling)

ScaleDownBillions

Character or String that signifies that a number represents billions

B

ScaleDownMillions

Character or String that signifies that a number represents millions

M

ScaleDownQuadrillions

Character or String that signifies that a number represents quadrillions

Q

ScaleDownThousands

Character or String that signifies that a number represents thousands

K

ScaleDownTrillions

Character or String that signifies that a number represents trillions

T

OracleDateFormat

Oracle date format

null String

JavaDateFormat

Java date format

null String

The ViewFormat object has special properties that indicate whether one of the number formatting properties has been set. These properties end in "used." You should not have to worry about these properties at all. Whenever you set one of the number formatting properties, the "used" property is automatically set. The ViewFormat object uses the "used" properties internally when it merges another ViewFormat.

Merging ViewFormat objects

ViewFormat objects implement the Mergeable interface, which allows them to merge into each other. For example, you might have a ViewFormat that sets properties for currency, which you use for currency data. You might have a separate ViewFormat that you use to specify the scaling properties that you use. You can combine these two ViewFormat objects into a single ViewFormat that sets both the currency properties and the scaling properties. The merge method of the ViewFormat combines the properties of two different ViewFormat objects.

If two ViewFormat objects set the same property, then the value from the ViewFormat that is passed as argument in the merge method takes effect. In the following example, the ScaleFactor setting from vf2 takes effect when it is merged into vf1. Because vf2 does not have the LeadingZero property explicitly set, the value from vf1 takes effect.


ViewFormat vf1 = new ViewFormat(); vf1.setScaleFactor(SCALEFACTOR_NONE); vf1.setLeadingZero(false); ViewFormat vf2 = new ViewFormat(); vf2.setScaleFactor(SCALEFACTOR_THOUSANDS); // ScaleFactor will be SCALEFACTOR_THOUSANDS // LeadingZero will be falsevf1.merge(vf2);

Using Rules to apply context-specific formatting

You can instruct the graph to apply special formatting under particular circumstances. For example, you might have a particular ViewFormat that you use only for measures that have currency data. This ViewFormat might set NumberType and the currency symbol properties. You might further have a ViewFormat that you want to use only for measures that have currency data in Japanese Yen. This ViewFormat might set only the currency symbol properties. You can provide rules that specify both the formatting to apply and the circumstances in which to apply it.

Creating Rules for Formatting Dataviews
Example: Setting the Number Format for a Measure in a Graph
Formatting Numbers in Graphs
How Rules Work
Rule Concepts