NumberFormatter

Type class

NumberFormatter class. Formats numbers according to specified formats.

@todo Apply translations to suffixes/prefixes

Sources

NumberFormatter can be used (imported) via one of the following packages.

// NumberFormatter is available in all of the following modules.
// You only need to import one of them.

/**
 * --------------------------------------------------------
 * Import from: "core.ts"
 * Use like: am4core.NumberFormatter
 * --------------------------------------------------------
 */
import * as am4core from "@amcharts/amcharts4/core";

// NumberFormatter is available in all of the following modules.
// You only need to import one of them.

/**
 * --------------------------------------------------------
 * Include via: <script src="core.js"></script>
 * Access items like: am4core.NumberFormatter
 * --------------------------------------------------------
 */

Inheritance

NumberFormatter extends BaseObject.

NumberFormatter is not extended by any other symbol.

Properties

bigNumberPrefixes
#

Type INumberSuffix[]

Prefixes for big numbers.

It's an array of objects of number/prefix pairs.

[
  { "number": 1e+3, "suffix": "K" },
  { "number": 1e+6, "suffix": "M" },
  { "number": 1e+9, "suffix": "G" },
  { "number": 1e+12, "suffix": "T" },
  { "number": 1e+15, "suffix": "P" },
  { "number": 1e+18, "suffix": "E" },
  { "number": 1e+21, "suffix": "Z" },
  { "number": 1e+24, "suffix": "Y" }
]

If the number is bigger than the number ir will be converted to the appropriate bigger number with prefix.

E.g. as per above 1500 will be converted to 1.5K.

Please note that for this transformation to be enabled, you need to enable it specific modifier in your format setting.

The modifier for big/small number modification is "a":

{myfield.formatNumber("#,###.00a")}

@see This link Tutorial on number formatting

bytePrefixes
#

Type INumberSuffix[]

Basically the same as bigNumberPrefixes, except base for calculation is not thousand but byte (1024).

The modifier is "b".

{myfield.formatNumber("#,###.00b")}

The above 2048 will change to 2K.

@see This link Tutorial on number formatting

clonedFrom
#

Type $type.Optional < this >

Inherited from BaseObject

Reference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed.

config
#

Type object

Inherited from BaseObject

Use this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc.

Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations.

id
#

Type $type.Optional < string >

Inherited from BaseObject

Sets the user-defined id of the element.

language
#

Type Language

A reference to Language instance.

Formatter will use language to translate various items, like number suffixes, etc.

negativeBase
#

Type number

Negative base for negative numbers.

@default
@see This link Tutorial on number formatting

numberFormat
#

Type string

Number format.

@see This link Tutorial on number formatting

smallNumberPrefixes
#

Type INumberSuffix[]

Prefixes for big numbers.

It's an array of objects of number/prefix pairs.

[
  { "number": 1e-24, "suffix": "y" },
  { "number": 1e-21, "suffix": "z" },
  { "number": 1e-18, "suffix": "a" },
  { "number": 1e-15, "suffix": "f" },
  { "number": 1e-12, "suffix": "p" },
  { "number": 1e-9, "suffix": "n" },
  { "number": 1e-6, "suffix": "μ" },
  { "number": 1e-3, "suffix": "m" }
]

If the number is smaller than the number ir will be converted to the appropriate smaller number with prefix.

E.g. as per above 0.0015 will be converted to 1.5m.

Please note that for this transformation to be enabled, you need to enable it specific modifier in your format setting.

The modifier for big/small number modification is "a":

{myfield.formatNumber("#,###.00a")}

IMPORTANT: The order of the suffixes is important. The list must start from the smallest number and work towards bigger ones.

@see This link Tutorial on number formatting

sprite
#

Type $type.Optional < Sprite >

Holds reference to parent Sprite object.

uid
#

Type string

Inherited from BaseObject

Returns object's internal unique ID.

There are 4 inherited items currently hidden from this list.

Methods

constructor()

#

Returns NumberFormatter

Constructor

clone(

cloneId?: string

)

#

Returns this

Inherited from BaseObject

Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.

copyFrom(

object: this

)

#

Returns void

Inherited from BaseObject

Copies all properties and related data from different element.

dispose()

#

Returns void

format(

value: number | string,
format?: string

)

#

Returns string

Formats the number according to specific format.

getCurrentThemes()

#

Returns ITheme[]

Inherited from BaseObject

Returns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide.

isDisposed()

#

Returns boolean

Inherited from BaseObject

Returns if this object has been already been disposed.

There are 4 inherited items currently hidden from this list.

Events

NumberFormatter does not have any events.

Adapters

NumberFormatter does not have any adapters.