AnyChart
API Reference
Still have questions?
Contact support
Top
You are looking at an outdated v7 version of this document. Switch to the v8 version to see the up to date information.

namespace anychart.format Improve this Doc

Namespace for format.

Functions Overview

date()Formats date by pattern.
dateTime()Formats date time by pattern.
getDateTimeFormat()Gets datatime format from locale by identifier and index.
getDateTimeFormats()Gets all datatime formats from locale by identifier.
getIntervalIdentifier()Get interval identifier by unit name.
getMessage()Returns localized message if the translation is provided in messages section of output locale.
inputBaseDate()Input base date settings.
inputDateTimeFormat()Input date time format
inputLocale()Input format settings to be used.
number()Formats number.
outputDateFormat()Getter only current output date format.
outputDateTimeFormat()Getter for the output date and time format.
outputLocale()Output format settings to be used.
outputTimeFormat()Getter only current output time format.
outputTimezone()Output timezone settings.
parseDateTime()Parses input value to date.
parseNumber()Parses value to number according to locale set.
subs()Formats for string substitution.
time()Formats time by pattern.

Typedefs Overview

anychart.format.DateTimeLocaleType definition for date time localization.
anychart.format.LocaleType definition for localization.
anychart.format.NumberLocaleType definition for number locale.
anychart.format.localesContains a list of the used localizations.

Classes Overview

anychart.format.ContextCommon format context class.

Functions Description

date

Formats date by pattern.
The same that anychart.format.dateTime but with the anychart.format#outputDateFormat as default datetime format.

Params:

NameTypeDescription
datenumber | DateUTC timestamp or Date object.
timeZonenumberAdjust with time zone. Indicate minutes WEST of UTC to be used as a constant time zone offset.
localestring | anychart.format.LocaleLocale to be used.

Returns:

string - Formatted value.

dateTime

Formats date time by pattern.

Params:

NameTypeDescription
datenumber | DateUTC timestamp or Date object.
formatstringFormat of date ['yyyy.MM.dd'].
timeZonenumberAdjust with time zone. Indicate minutes WEST of UTC to be used as a constant time zone offset.
localestring | anychart.format.LocaleLocale to be used.

Returns:

string - Formatted value.

getDateTimeFormat

Gets datatime format from locale by identifier and index. To get all formats use anychart.format#getDateTimeFormats.

Params:

NameTypeDefaultDescription
identifierstring
Use anychart.format#getIntervalIdentifier to get correct identifier
indexnumber
0
If locale has more than one format.
localeanychart.format.Locale
Locale to be used.

Returns:

string -
anychart.format.getDateTimeFormat
// for example in 'de-de' locale defined
// 'year_day': ['EEEE, y MMMM dd', 'yy MM dd', 'yyyy MMMM dd']
var identifier = anychart.format.getIntervalIdentifier('days','years');
var format = anychart.format.getDateTimeFormat(identifier, 2, 'de-de');
// format = 'yyyy MMMM dd'

getDateTimeFormats

Gets all datatime formats from locale by identifier. To get one format by index use anychart.format#getDateTimeFormat.

Params:

NameTypeDescription
identifierstringUse anychart.format#getIntervalIdentifier to get correct identifier
localeanychart.format.LocaleLocale to be used.

Returns:

string -
anychart.format.getDateTimeFormat
// for example in 'de-de' locale defined
// 'year_day': ['EEEE, y MMMM dd', 'yy MM dd', 'yyyy MMMM dd']
var identifier = anychart.format.getIntervalIdentifier('days','years');
var allFormats = anychart.format.getDateTimeFormat(identifier, 'de-de');
// allFormats = ['EEEE, y MMMM dd', 'yy MM dd', 'yyyy MMMM dd']

getIntervalIdentifier

Get interval identifier by unit name.

Params:

NameTypeDescription
intervalUnitanychart.enums.IntervalName of unit interval.
parentIntervalUnitanychart.enums.IntervalName of parent unit interval.

Returns:

string - Correct interval identifier by unit name.
Use anychart.format.getIntervalIdentifier
anychart.format.getIntervalIdentifier('day','year');
anychart.format.getIntervalIdentifier('d','y');
// returns 'year_day'

getMessage

Returns localized message if the translation is provided in messages section of output locale.

Params:

NameTypeDescription
keywordanychart.enums.IntervalKeyword.

Returns:

string - Message from current locale by keyword or a keyword itself if a message doesn't exist.

inputBaseDate

Getter for the input base date.

Returns:

Date - The input base date.Date -
Setter for the input base date.

Params:

NameTypeDescription
valueDate | number

Returns:

Date - The input base date.
Example
anychart.format.inputBaseDate(Date.UTC(2010, 10, 15, 16, 23, 10, 113));
// Try to parse
anychart.format.parseDateTime("13:31:16", "HH:mm:ss");
// Returns Date.UTC(2010, 10, 15, 13, 31, 16, 113)

inputDateTimeFormat

Getter for the input date time format.

Returns:

string - The date time format.
See listing
var dateTimeFormat = anychart.format.inputDateTimeFormat();
Setter for the input date time format. Has priority over the format of localization.

Params:

NameTypeDescription
valuestringInput date time format for parsing

Returns:

string - The date time format.

inputLocale

Getter for the input format settings.

Returns:

string | anychart.format.Locale - The localization name or settings.
See listing
var currentInputLocale = anychart.format.inputLocale();
Setter for the input format settings.

Params:

NameTypeDefaultDescription
valuestring | anychart.format.Locale
"default"
Localization name or settings.

Returns:

string | anychart.format.Locale - The localization name or settings.

number

Formats number with given settings.

Params:

NameTypeDefaultDescription
numbernumber
Number for formatting.
decimalsCountOrLocalnumber | anychart.format.NumberLocale | string
2
Desired number of decimals or localization.
decimalPointstring
"."
String to modify the decimal separator.
groupsSeparatorstring
""
String to separate every three digits.
scaleObject | boolean
false
Automatic scaling (divides by factor and substitutes suffix). If pass "true", will be used default scale.
zeroFillDecimalsboolean
false
Whether to fill in the remaining decimal places zeros.
scaleSuffixSeparatorstring
""
Additive between the suffix of scale and the number. Works only with scaling.
useBracketsForNegativeboolean
Whether to use brackets for negative value.

Returns:

string - Formatted value.
Formats number using object.

Params:

NameTypeDescription
numbernumberNumber for formatting.
objectanychart.format.NumberLocaleObject with settings.

Returns:

string - Formatted value.

outputDateFormat

Getter only current output date format.

Returns:

string - The output date format.
Setter only output date format.

Params:

NameTypeDescription
valuestringDate format for parsing.

outputDateTimeFormat

Getter for the output date and time format.

Returns:

string - The date time format.
Output date and time format. Has priority over the format of localization.

Params:

NameTypeDescription
valuestringDate time format for parsing.

outputLocale

Getter for the output format settings.

Returns:

string | anychart.format.Locale - The localization name or settings.
See listing
var currentOutputLocale = anychart.format.outputLocale();
Setter for the output format settings.

Params:

NameTypeDescription
valuestring | anychart.format.LocaleLocalization name (from anychart.format#locales) or object of localization for output.

Returns:

string | anychart.format.Locale - The localization name or settings.

outputTimeFormat

Getter only current output time format.

Returns:

string - The current time format.
Setter only output time format.

Params:

NameTypeDescription
valuestringTime format for parsing

outputTimezone

Getter for the output offset.

Returns:

number - The output offset.
See listing
var currentOutputTimezone = anychart.format.outputTimezone();
Setter for the output offset.
Adjusts time zone by value in minutes. Indicate minutes WEST of UTC to be used as the constant time zone offset.

Params:

NameTypeDefaultDescription
valuenumber
0
Value for adjusting time zone in minutes.

Returns:

number - The output offset.

parseDateTime

Parses input value to date.

Params:

NameTypeDescription
value*Input value.
formatstringFormat to be parsed. If undefined, anychart.format.inputDateTimeFormat is be used.
baseDateDateDate object to hold the parsed date. Used in cases when input value doesn't contain information about a year or a month or else. If parsing is successful this object contains absolutely the same values of date time units as the return value.
NOTE: If not Date, Date.UTC(currentYear, currentMoth) is be used.
localestring | anychart.format.LocaleLocale to be used. If not set, anychart.format.inputLocale is be used.

Returns:

Date - Parsed date or null if got wrong input value.

parseNumber

Parses value to number according to locale set.

Params:

NameTypeDescription
value*Value to be parsed.
localeanychart.format.NumberLocale | stringNumber locale to be used. If not defined, anychart.format.input.numberFormat will be used.

Returns:

number - Parsed value. NaN if value could not be parsed.

subs

Formats for string substitution. For example: subs("foo%s hot%s", "bar", "dog") becomes "foobar hotdog".

Params:

NameTypeDescription
stringstringThe string containing the pattern.
var_args*The items to substitute into the pattern.

Returns:

string - A copy of {@code str} in which each occurrence of {@code %s} has been replaced an argument from {@code var_args}.

time

Formats time by pattern.
The same that anychart.format.dateTime but with the anychart.format#outputTimeFormat as default datetime format.

Params:

NameTypeDescription
datenumber | DateUTC timestamp or Date object.
timeZonenumberAdjust with time zone. Indicate minutes WEST of UTC to be used as a constant time zone offset.
localestring | anychart.format.LocaleLocale to be used.

Returns:

string - Formatted value.