CFXValueFormat Class Reference

Inherits from
Conforms to
Framework
Availability
Available in iOS 5.0 and later.
Companion guide
Declared in
ChartFX.h

Overview

The ValueFormat members allow you to format values as numbers, dates, currency, scientific and time. These properties may be applied to axis labels (using the labelsFormat property of the CFXAxis class), and point labels (using the dataFormat of the CFXAxis class).

Properties

customFormat

Gets or sets a custom format to the selected label, tooltip or value.

@property(nonatomic) NSString *customFormat
Discussion

This property must be invoked before data has been bound or passed to the chart using the dataSource or data properties of the CFXChart respectively.

When a CustomFormat is applied to a selected axis, any formatting assigned using the decimals property will be ignored.

The following table shows the characters you can use to create user-defined number formats and the meaning of each:

Character 0 ( Digit placeholder).

Display a digit or a zero. If there is a digit in the expression being formatted in the position where the 0 appears in the format string, display it; otherwise, display a zero in that position. If the number being formatted has fewer digits than there are zeros (on either side of the decimal) in the format expression, leading or trailing zeros are displayed. If the number has more digits to the right of the decimal separator than there are zeros to the right of the decimal separator in the format expression, the number is rounded to as many decimal places as there are zeros. If the number has more digits to the left of the decimal separator than there are zeros to the left of the decimal separator in the format expression, the extra digits are displayed without modification.

Character # (Digit placeholder)

Display a digit or nothing. If there is a digit in the expression being formatted in the position where the # appears in the format string, display it; otherwise, display nothing in that position. This symbol works like the 0 digit placeholder, except that leading and trailing zeros aren't displayed if the number has the same or fewer digits than there are # characters on either side of the decimal separator in the format expression.

Character . (Decimal placeholder)

The decimal placeholder determines how many digits are displayed to the left and right of the decimal separator. If the format expression contains only number signs to the left of this symbol, numbers smaller than 1 begin with a decimal separator. If you want a leading zero to always be displayed with fractional numbers, use 0 as the first digit placeholder to the left of the decimal separator instead. The actual character used as a decimal placeholder in the formatted output depends on the Number Format specified for the development workstation. For some countries, a comma is used as the decimal separator.

Character , (Thousand separator)

The thousand separator separates thousands from hundreds within a number that has four or more places to the left of the decimal separator. Standard use of the thousand separator is specified if the format contains a comma surrounded by digit placeholders (0 or #). Two adjacent commas or a comma immediately to the left of the decimal separator (whether or not a decimal is specified) means "scale the number by dividing it by 1000, rounding as needed." You can scale large numbers using this technique. For example, you can use the format string "##0,," to represent 100 million as 100. Numbers smaller than 1 million are displayed as 0. Two adjacent commas in any position other than immediately to the left of the decimal separator are treated simply as specifying the use of a thousand separator. The actual character used as the thousand separator in the formatted output depends on the Number Format specified in the International section of the Control Panel. For some countries, a period is used as the thousand separator.

Character ; (expression separator)

The following example has two sections: the first defines the format for positive values and zeros; the second section defines the format for negative values. "$#,##0;($#,##0)"

If you include semicolons with nothing between them, the missing section is printed using the default format. For example, the following format displays positive as currency and negative values using the default format: "$#,##0;"

The following table shows the characters you can use to create user-defined date/time formats and the meaning of each, but check Xcode and Objective-C documentation for updated information:

Character C

Display the date as ddddd and display the time as t t t t t, in that order. Only date information is displayed if there is no fractional part to the date serial number; only time information is displayed if there is no integer portion.

Date Parameters:

Character d

Display the day as a number without a leading zero (1-31).

Character dd

Display the day as a number with a leading zero (01-31).

Character ddd

Display the day as an abbreviation (Sun-Sat).

Character dddd

Display the day as a full name (Sunday-Saturday).

Character ddddd

Display a date serial number as a complete date (including day, month, and year) formatted according to the Short Date setting in the International section of the Windows Control Panel. The default Short Date format is m/d/yy.

Character dddddd

Display a date serial number as a complete date (including day, month, and year) formatted according to the Long Date setting in the International section of the Control Panel. The default Long Date format is mmmm dd, yyyy.

Character M

Display the month as a number without a leading zero (1-12).

Character MM

Display the month as a number with a leading zero (01-12).

Character MMM

Display the month as an abbreviation (Jan-Dec).

Character MMMM

Display the month as a full month name (January-December).

Character y

Display the day of the year as a number (1-366).

Character yy

Display the year as a two-digit number (00-99).

Character yyyy

Display the year as a four-digit number (100-9999).

Time Parameters:

Character h

Display the hour as a number without leading zeros (0-11) using a 12-hour clock

Character hh

Display the hour as a number with leading zeros (00-11) using a 12-hour clock

Character H

Display the hour as a number (0-23) using a 24-hour clock.

Character HH

Display the hour as a number with leading zeros (00-23) using a 24-hour clock.

Character m

Display the minute as a number without leading zeros (0-59).

Character mm

Display the minute as a number with leading zeros (00-59).

Character s

Display the second as a number without leading zeros (0-59).

Character ss

Display the second as a number with leading zeros (00-59).

Character t

One character time-marker string, such as A or P

Character tt

Multicharacter time-marker string such as AM or PM

Format Display

m/d/yy 12/7/58

d-MMMM-yy 7-December-58

d-MMMM 7 December

MMMM-yy December 58

h:mm 20:50

h:mm:ss 20:50:35

m/d/yy h:mm 12/7/58 20:50

Declared In
ChartFX.h

decimals

Gets or sets the number of decimals for the selected label, tooltip or value.

@property(nonatomic) int decimals
Discussion

When a customFormat is applied to a selected axis, any formatting assigned using the Decimals property will be ignored.

Declared In
ChartFX.h

format

Used to format the selected label, tooltip or value to numbers, date, time, scientific or currency.

@property(nonatomic) CFXAxisFormat format
Declared In
ChartFX.h

isDate

Returns a value indicating whether or not a value is a Date.

@property(nonatomic) BOOL isDate
Availability
  • Available in iOS 5.0 and later.
Declared In
ChartFX.h

isDateTime

Returns a value indicating whether or not a value is a DateTime.

@property(nonatomic) BOOL isDateTime
Availability
  • Available in iOS 5.0 and later.
See Also
Declared In
ChartFX.h

isPercentage

Returns a value indicating whether or not a value is a Percentage.

@property(nonatomic) BOOL isPercentage
Declared In
ChartFX.h

isTime

Returns a value indicating whether or not a value is a Time.

@property(nonatomic) BOOL isTime
Declared In
ChartFX.h

Instance Methods

formatDateTime:

Returns an expression formatted as a date or time.

- (NSString *)formatDateTime:(NSDate *)dt
Parameters
dt
Date expression to be formatted.
Discussion

The FormatDateTime method returns a string of an NSDate with the same format as the selected Axis.

The formatNumber method returns a string of a double value with the same format as the selected Axis.

The format property is used to format the selected label, tooltip or value to numbers, date, time, scientific or currency.

The customFormat property gets or sets a custom format to the selected label, tooltip or value.

The decimals property gets or sets the number of decimals for the selected label, tooltip or value.

The dataFormat and labelsFormat properties are used to access the respective ValueFormat objects in a chart.

Availability
  • Available in iOS 5.0 and later.
Declared In
ChartFX.h

formatNumber:

Returns an expression formatted as a number.

- (NSString *)formatNumber:(double *)d
Parameters
d
Expression to be formatted.
Discussion

The FormatNumber method returns a string of a double value with the same format as the selected Axis.

The formatDateTime method returns a string of an NSDate with the same format as the selected Axis.

The format property is used to format the selected label, mouseover tip or value to numbers, date, time, scientific or currency.

The customFormat property gets or sets a custom format to the selected label, mouseover tip or value.

The decimals property gets or sets the number of decimals for the selected label, mouseover tip or value.

The dataFormat and labelsFormat properties are used to access the respective ValueFormat objects in a chart.

Declared In
ChartFX.h

parse:

Converts a formatted expression to a number.

- (double)parse:(NSString *)s
Parameters
s
Formatted expression to be parsed.
Discussion

The Parse method expects a string of the same format as configured for the selected axis. This method is also culturally aware.

The format property is used to format the selected label, mouseover tip or value to numbers, date, time, scientific or currency.

The formatDateTime method returns a string of an NSDate with the same format as the selected Axis.

The formatNumber method returns a string of a double value with the same format as the selected Axis.

The dataFormat and labelsFormat properties are used to access the respective ValueFormat objects in a chart.

Declared In
ChartFX.h

Constants

CFXAxisFormat

Defines the valid formats to may be apply to an axis.

typedef enum {
   CFXNone,
   CFXNumber,
   CFXCurrency,
   CFXScientific,
   CFXPercentage,
   CFXDate,
   CFXLongDate,
   CFXTime,
   CFXDateTime
} CFXAxisFormat;
Constants
CFXNone
Displays a Number without formatting.
CFXNumber
Displays a Number, as defined in the International section of the Control Panel.
CFXCurrency
Displays Currency, as defined in the International section of the Control Panel.
CFXScientific
Displays standard scientific notation.
CFXPercentage
Displays numbers multiplied by 100 with a percent sign (%) appended to the right; display two digits to the right of the decimal separator.
CFXDate
Displays a Short Date, as defined in the International section of the Control Panel.
CFXLongDate
Displays a Long Date, as defined in the International section of the Control Panel.
CFXTime
Displays Time, as defined in the International section of the Control Panel.
CFXDateTime
Displays Date-Time, as defined in the International section of the Control Panel.
Declared In
chartfx.h