Formatting Numbers and Numeric Labels

In this section:

The following methods are supported for defining the format of data text and numeric chart labels:


Top of page

x
Preset Number Formats

You can use the following ...Format properties to select one of the preset patterns or to tell the graphing engine to use a format pattern:

The following methods can be used to set the format of labels on a specified axis and to specify custom data text formatting:

When you use these properties and methods, -2 or -1 tells the graphing engine that the format will be defined by one of the ...FormatPattern properties or methods. 0...21, 24...30 selects one of the formats shown in the following table.

Value

Format

Example

-2

#/100

Note: The number format is the custom format specified by setTextFormatPattern.

123 = 1.23

-1

#

Note: The number format is the custom format specified by setTextFormatPattern.

123 = 123

0/1=

#

123 = 123

2=

#%

123 = 12,300%

3=

#.#%

123 = 12,300.0%

4=

#.##%

123 = 12,300.00%

5=

$#.##

123 = $123.00

6=

$#

123 = $123

7=

#K (show K for values over 999)

1,000 = 1K

8=

$#K (show K for values over 999)

1,000 = $1K

9=

#M (show M for millions)

1,000,000 = 1M

10=

$#M (show M for millions)

1,000,000 = $1M

11=

#B (show B for billions)

1,000,000,000 = 1B

12=

$#B (show B for billions)

1,000,000,000 = $1B

13=

#T (show T for trillions)

1,000,000,000,000 = 1T

14=

$#T (show T for trillions)

1,000,000,000,000 = $1T

15=

Number with thousands separators, no decimal places.

1,234 = 1K

16=

Number with thousands separators, two decimal places.

1,234 = 1.23K

17=

General currency format for current locale.

 

18=

Short date format: MM/DD/YY.

10/01/03

19=

Medium date format: Mon. DD, YYYY.

Oct. 01, 2003

20=

Long date format: Month DD, YYYY.

October 01, 2003

21=

Full date format: Day, Month DD, YYYY.

Wednesday, October 01, 2003

24/25

#

Negative numbers are in brackets

-123= (123)

26

Number with thousands separators, no decimal places, negative numbers in brackets.

-1,234= (1K)

27

Number with thousands separators, two decimal places, negative numbers in brackets.

-1,234 = (1.23K)

28

#%/100

123 = 123%

29

#.#%/100

123 = 123.0%

30

#.##%/100

123 = 123.00%

Example:

The following example code selects the dollar format for data text labels:

setDataTextFormat(6);

bar graph with formatted data text labels



x
Number Format Patterns

You can use the following ...FormatPattern properties to specify a standard Java format pattern:

The following methods can be used to define format pattern strings:

When you use these properties, the PatternString defines the format of data text or labels in the following format:

pattern:= subpattern{;subpattern}
subpattern:= {prefix}integer{.fraction}{suffix}
prefix:= '\\u0000'..'\\uFFFD' - specialCharacters
suffix:= '\\u0000'..'\\uFFFD' - specialCharacters
integer:= '#'* '0'* '0'
fraction:= '0'* '#'*

Notation:

X*

Means there are 0 or more instances of X.

(X|Y)

Is either X or Y.

X..Y

Is any character from X up to Y, inclusive.

S - T

Are characters in S, except those in T.

The first subpattern is for positive numbers. The second (optional) subpattern is for negative numbers. In both cases, a comma (,) can occur inside the integer portion. Here are the special characters used in the parts of the subpattern, with notes on their usage.

0

Is a digit.

#

Is a digit, zero shows as absent.

.

Is a placeholder for decimal separator.

,

Is a placeholder for grouping separator.

;

Separates formats.

-

Is the default negative prefix.

%

Divides by 100 and show as percentage.

x

Determines that any other characters can be used in the prefix or suffix.

'

Is used to quote special characters in a prefix or suffix.

If there is no explicit negative subpattern, a minus sign (-) is prefixed to the positive form. That is, 0.00 alone is equivalent to 0.00;-0.00. Illegal formats, such as "#.#.#" or mixing '_' and '*' in the same format, will cause a ParseException. From that ParseException, you can find the place in the string where the error occurred. The grouping separator is commonly used for thousands, but in some countries for ten-thousands. The interval is a constant number of digits between the grouping characters, such as 100,000,000 or 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".

This class only handles localized digits where the 10 digits are contiguous in Unicode, from 0 to 9.



Example: Formatting a Pie Ring Label

The following commands use the setTextFormatPreset() and setTextFormatPattern() methods to set the pie ring label format to set the numeric format to ###,###:

setTextFormatPreset(getPieRingLabel(),-1);
setTextFormatPattern(getPieRingLabel(),"###,###");

The output shows that the pie ring label (the number at the center of the chart) is formatted with a comma as the group separator and no decimal digits:


Top of page

x
Special Formatting Using Macros

You can use the following properties in bubble, stock, and scatter graphs to apply special formatting to data text values:


WebFOCUS