DurationFormatter
Type class
DurationFormatter class. Formats numbers as durations.
1000 as 16:40
More info: Formatting Duration 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: am4core.DurationFormatter */Inheritance
DurationFormatter extends BaseObject.
DurationFormatter is not extended by any other symbol.
Properties
baseUnitType
TimeUnitDefault"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"
durationFormatType
stringIf set, this format will be used instead of the one determined dynamically based on the basedUnit and range of values.
More info: Formatting Duration Available fomatting codes
durationFormatsType
Partial<Record<TimeUnit,Partial<Record<TimeUnit,string>>>>Duration formats for various combination of base units.
languageType
$type.Optional<Language>Holds reference to
Languageobject.spriteType
$type.Optional<Sprite>Holds reference to parent
Spriteobject.
4 inherited items
clonedFromType
$type.Optional<this>Inherited fromBaseObjectReference 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.
configType
objectInherited fromBaseObjectUse 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.
idType
$type.Optional<string>Inherited fromBaseObjectSets the user-defined id of the element.
uidType
stringInherited fromBaseObjectReturns object's internal unique ID.
Methods
constructor()Returns
DurationFormatterConstructor
format(value:number|string,
format?:string,
base?:TimeUnit)Returns
stringFormats the number according as duration.
For example
1000(base unit seconds) would be converted to16:40as in 16 minutes and 40 seconds.More info: Formatting Duration Tutorial on duration formatting
getFormat(value:number,
maxValue?:number,
baseUnit?:TimeUnit)Returns
stringReturns appropriate default format for the value.
If
maxValueis sepcified, it will use that value to determine the time unit for the format.For example if your
baseUnitis"second"and you pass in10, 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
600asmaxValue, 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
numberConverts value to milliseconds according to
baseUnit.getValueUnit(value:number,
baseUnit?:TimeUnit)Returns
TimeUnitReturns value's closest denominator time unit, e.g 100 seconds is
"minute", while 59 seconds would still besecond.toTimeStamp(value:number,
baseUnit:TimeUnit)Returns
numberConverts numeric value to timestamp in milliseconds.
5 inherited items
clone(cloneId?:string)Returns
thisInherited fromBaseObjectMakes 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
voidInherited fromBaseObjectCopies all properties and related data from different element.
dispose()Returns
voidInherited fromBaseObjectDestroys this object and all related data.
getCurrentThemes()Returns
ITheme[]Inherited fromBaseObjectReturns 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
booleanInherited fromBaseObjectReturns if this object has been already been disposed.
Events
DurationFormatter does not have any events.