DurationFormatter

Type class

DurationFormatter class. Formats numbers as durations.

1000 as 16:40

Click here Tutorial on duration formatting

Sources

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

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

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

Inheritance

DurationFormatter extends BaseObject.

DurationFormatter is not extended by any other symbol.

Properties

baseUnit
#

Type TimeUnit

Default "s"

Base unit the values are in.

A base unit will be used to recalculate the numeric value to millisecond timestamps.

Available options:

  • "millisecond"
  • "second"
  • "minute"
  • "hour"
  • "day"
  • "week"
  • "month"
  • "year"

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.

durationFormat
#

Type string

If set, this format will be used instead of the one determined dynamically based on the basedUnit and range of values.

Click here Available fomatting codes

durationFormats
#

Type Partial < Record < TimeUnit, Partial < Record < TimeUnit, string > > > >

Duration formats for various combination of base units.

id
#

Type $type.Optional < string >

Inherited from BaseObject

Sets the user-defined id of the element.

language
#

Type $type.Optional < Language >

Holds reference to Language object.

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

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.

constructor()

#

Returns DurationFormatter

Constructor

copyFrom(

object: this

)

#

Returns void

Inherited from BaseObject

Copies all properties and related data from different element.

dispose()

#

Returns void

Inherited from BaseObject

Destroys this object and all related data.

format(

value: number | string,
format?: string,
base?: TimeUnit

)

#

Returns string

Formats the number according as duration.

For example 1000 (base unit seconds) would be converted to 16:40 as in 16 minutes and 40 seconds.

Click here Tutorial on duration formatting

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.

getFormat(

value: number,
maxValue?: number,
baseUnit?: TimeUnit

)

#

Returns string

Returns appropriate default format for the value.

If maxValue is sepcified, it will use that value to determine the time unit for the format.

For example if your baseUnit is "second" and you pass in 10, you will get "10".

However, you might want it to be formatted in the context of bigger scale, say 10 minutes (600 seconds). If you pass in 600 as maxValue, all values, including small ones will use format with minutes, e.g.:

00:10, 00:50, 12: 30, etc.

getMilliseconds(

value: number,
baseUnit?: TimeUnit

)

#

Returns number

Converts value to milliseconds according to baseUnit.

getValueUnit(

value: number,
baseUnit?: TimeUnit

)

#

Returns TimeUnit

Returns value's closest denominator time unit, e.g 100 seconds is "minute", while 59 seconds would still be second.

isDisposed()

#

Returns boolean

Inherited from BaseObject

Returns if this object has been already been disposed.

toTimeStamp(

value: number,
baseUnit: TimeUnit

)

#

Returns number

Converts numeric value to timestamp in milliseconds.

There are 5 inherited items currently hidden from this list.

Events

DurationFormatter does not have any events.

Adapters

DurationFormatter does not have any adapters.