The following components in a graph can display numbers in different formats.
X1TickLabel
(the format is determined in the X1Axis
component)
Y1TickLabel
(the format is determined in the Y1Axis
component)
Y2TickLabel
(the format is determined in the Y2Axis
component)
SliceLabel
MarkerText
-- can have different formats for different situations:
Values in series that are assigned to the Y1-axis
Values in series that are assigned to the Y2-axis
X-axis values in a scatter, bubble, or polar graph
Z values (represented by the size of the marker) in bubble graphs
Values that represent stock volume in a stock graph
The constructor for each component that has a number format creates a default
ViewFormat
. To change the format for the component, you get the
ViewFormat
for the component and set the property in the ViewFormat
.
The following example sets the NumberType
property for the Y2-axis.
ViewFormat vf = graph.getY2Axis().getViewFormat(); vf.setNumberType(NUMTYPE_CURRENCY);
You can use the same ViewFormat
for more than one component by calling the
setViewFormat
method, as shown in the following code sample.
graph.getY1Axis().setViewFormat(graph.getY2Axis.getViewFormat());
The following code shows how to set properties that format the tick labels along the Y1-axis.
This code sets the NumberType
property for currency, and it sets the currency
properties. This example assumes that the graph variable is graph
.
ViewFormat vfY1 = graph.getY1Axis().getViewFormat(); vfY1.setNumberType(NUMTYPE_CURRENCY); vfY1.setCurrencySymbol("Dollars"); vfY1.setPosCurFmt(POS_CURFMT_NUM_SPAC_CUR); vfY1.setNegCurFmt(NEG_CURFMT_NEG_NUM_SPAC_CUR); vfY1.setDecimalDigit(0);
This code displays currency values along the Y1-axis as in the following sample values:
100 Dollars
-100 Dollars
Slice labels can display the name of the series that each slice represents, the percentage of
the group total that each slice represents, the actual value of the slice, or both the series
label and the percentage of the group total. By default, the slice labels display the percentage
of the group total. You can call the setTextType
method of the
SliceLabel
component to specify the contents of the labels.
Also by default, the graph format manager reads the value of the TextType
property of the SliceLabel
to know how to format the numbers that are displayed in
the slice labels. For example, if the TextType
property is set to display
percentages or to display percentages and text, the format manager sets the
NumberType
property of the ViewFormat
to NUMTYPE_CURRENCY
and the CurrencySymbol
property to the percent sign (%), to display the values as
percentages. If TextType
is set to show data values, text, or both, then the
NumberType
property retains its default value of NUMTYPE_GENERAL
, and
the percent sign does not appear in the labels. After its automatic formatting, the format
manager merges the ViewFormat
for the SliceLabel
with the
ViewFormat
that it has been working with; this gives you control over the final
values of the ViewFormat
properties.
The following code sample assumes that you give your users control over the
TextType
property of the slice labels. It also assumes that you want to format the
numbers that appear in slice labels, whether they are percentages or actual data values.
And it assumes that your graph variable is graph
.
int sliceTextType = graph.getSliceLabel().getTextType(); ViewFormat vfSliceLabel = graph.getSliceLabel().getViewFormat(); // if user has chosen to display percent values if (sliceTextType == BaseGraphComponent.LD_PERCENT || sliceTextType == BaseGraphComponent.LD_PERCENT_TEXT){ // then display like so: "50 percent" vfSliceLabel.setCurrencySymbol("percent"); vfSliceLabel.setPosCurFmt(POS_CURFMT_NUM_SPAC_CUR); } // if user has chosen to display actual values if (sliceTextType == BaseGraphComponent.LD_VALUE){ // display the values as currency, like so: "475 Dollars" // or, for negatives, "-475 Dollars" vfSliceLabel.setNumberType(NUMTYPE_CURRENCY); vfSliceLabel.setCurrencySymbol("Dollars"); vfSliceLabel.setPosCurFmt(POS_CURFMT_NUM_SPAC_CUR); vfSliceLabel.setNegCurFmt(NEG_CURFMT_NEG_NUM_SPAC_CUR); vfSliceLabel.setDecimalDigit(0); }
The following example code shows how to specify the display of four decimal digits for marker text in all of the situations in which the marker text is displayed.
MarkerText mtext = graph.getMarkerText(); mtext.getViewFormat(VF_X1).setDecimalDigits(4); mtext.getViewFormat(VF_Y1).setDecimalDigits(4); mtext.getViewFormat(VF_Y2).setDecimalDigits(4); mtext.getViewFormat(VF_Z).setDecimalDigits(4); mtext.getViewFormat(VF_STOCK_VOLUME).setDecimalDigits(4);
Creating Rules for Formatting
Dataviews
Example: Setting the Number Format for
a Measure in a Graph
How Rules Work
Rule Concepts
Using the ViewFormat Object to
Format Numbers