Root
Type class
The root of a chart: it ties the chart to an HTML element and holds its global settings, formatters, locale and themes.
More info: Getting started: root element
Sources
Root can be used (imported) via one of the following packages.
// Import Rootimport * as am5 from "@amcharts/amcharts5";
// Create Rootam5.Root.new(root, { // ... config if applicable});<!-- Load Root --><script src="index.js"></script>
<script>// Create Rootam5.Root.new(root, { // ... config if applicable});</script>Inheritance
Root does not extend any other symbol.
Root is not extended by any other symbol.
Properties
autoResizeType
booleanDefaulttrueResizes the chart automatically when its container's size changes. With
false, callresize()to resize it.containerType
ContainerThe main container: charts and other elements go into its
children.dateFormatterType
DateFormatterDefaultDateFormatter.new(this, {})Date/time formatter.
More info: Formatting dates
defaultRendererStaticType
IRendererClassDefaultCanvasRendererSince 5.21.0Renderer for Roots that do not set
renderer.domType
HTMLElementThe HTML element the chart is in.
durationFormatterType
DurationFormatterDefaultDurationFormatter.new(this, {})Duration formatter.
More info: Formatting dates
entitiesByIdType
objectSince 5.11.0Objects of this root that have an
idsetting, by thatid.eventsType
EventDispatcherDefaultnew EventDispatcher()Root's event dispatcher.
More info: Events
fpsType
number|undefinedMaximum frames per second. When not set, the chart renders on every animation frame of the browser.
Each frame waits
1000 / fpsmilliseconds after the previous one is drawn, then for the screen's next refresh, so the rate achieved is lower:fps: 30gives about 20 on a 60 Hz screen.More info: Root element: performance
gridLayoutType
GridLayoutDefaultGridLayout.new()A shared
GridLayoutfor aContainer'slayoutsetting.horizontalLayoutType
HorizontalLayoutDefaultHorizontalLayout.new()A shared
HorizontalLayoutfor aContainer'slayoutsetting.interfaceColorsType
InterfaceColorsColors of the chart's interface: text, grid, buttons and other controls.
More info: Colors, gradients, and patterns: interface colors
localeType
ILocaleDefaultenLocale for the chart's texts and formatting. English by default.
More info: Locales
nonceType
undefined|stringNonce for the
<style>elements the chart adds to the page, for pages with a strict Content Security Policy.numberFormatterType
NumberFormatterDefaultNumberFormatter.new(this, {})Number formatter.
More info: Formatting numbers
settingsType
IRootSettingsThe Root's settings.
skipRenderFrameType
booleanDefaultfalsesystemTooltipType
TooltipSince 5.14.0A shared
Tooltip(theme tag"system") for interface elements such as the logo and buttons, created on first use.tabindexType
numberDefault0Tab index for the whole chart.
More info: Accessibility
tapToActivateType
booleanDefaultfalseSince 5.2.9Makes touch gestures such as zoom and pan work only after a tap on the chart, so the page can still be scrolled over it.
More info: Root element: touch related options
tapToActivateTimeoutType
numberDefault3000Since 5.2.9How long in milliseconds the chart stays active after the last touch, with
tapToActivate, before handing touch gestures back to the page.0keeps it active until a tap outside the chart.More info: Root element: touch related options
timezoneType
TimezoneSince 5.1.0Time zone to show dates in, instead of the user's local one. Set it to a
Timezonewith an IANA name, e.g.am5.Timezone.new("America/Vancouver"). For UTC,utcis faster.Every date is converted, which can slow down charts with large data sets.
More info: Root element: time zone
tooltipContainerType
ContainerThe
Containertooltips are drawn in, above the chart.updateTickType
booleanWhether the chart updates and redraws.
Stops the chart from updating and redrawing with
false, until set back totrue.utcType
booleanDefaultfalseTreats dates as UTC instead of the user's local time, when formatting and parsing them and when placing date axis grid. It takes precedence over
timezone.More info: Formatting dates: utc and time zones
verticalLayoutType
VerticalLayoutDefaultVerticalLayout.new()A shared
VerticalLayoutfor aContainer'slayoutsetting.
Methods
dispose()Returns
voidDisposes the Root and everything in it, and removes the chart from the page.
documentPointToRoot(point:IPoint)Returns
IPointConverts a point from viewport coordinates, such as a pointer event's
clientXandclientY, to coordinates within the root.eachFrame(f: (currentTime:number) =>void)Returns
IDisposerCalls a function on every frame, which keeps the chart rendering, until the returned disposer is disposed.
focused(target:Sprite)Returns
booleanReturns
trueiftargetis currently focused.height()Returns
numberReturns the chart's height in pixels: the container's, or the one from
calculateSizeif set.isDisposed()Returns
booleanReturns
trueif the Root is disposed.markDirtyGlobal(container?:Container)Returns
voidMakes every element inside a container update and re-measure on the next frame.
moveDOM(id:string|HTMLElement)Returns
voidMoves the chart to another HTML element and resizes it to fit there.
Nothing happens if no element with that
idexists.new(id:string|HTMLElement,
settings?:IRootSettings)StaticReturns
RootCreates a Root in an HTML element. An element can hold only one Root:
creating another one there throws an error, unless
am5.registry.autoDisposeistrue.readerAlert(text:string)Returns
voidMakes screen readers read out a message.
More info: Accessibility
resize()Returns
voidResizes the chart to fit its container. Call it after the container's size changes when
autoResizeisfalse.rootPointToDocument(point:IPoint)Returns
IPointConverts a point from coordinates within the root to viewport coordinates, as in a pointer event's
clientXandclientY.setThemes(themes:Array)Returns
voidSets the chart's themes, replacing any set before.
More info: Themes
width()Returns
numberReturns the chart's width in pixels: the container's, or the one from
calculateSizeif set.
Events
Add event handlers to Root object using its events.on() method. Read about adding event handlers.