Annotator
Type class
Lets the user draw annotations over the chart: shapes, lines, arrows, text and callouts. They are drawn as part of the chart, so they are exported with it.
Annotations can be pinned to what is under them, so they move and zoom with it: values of an XY chart's axes, a place on a map, a pie slice, or a hierarchy or flow node.
More info: Annotator
Sources
Annotator can be used (imported) via one of the following packages.
// Import Annotatorimport * as am5plugins_exporting from "@amcharts/amcharts5/plugins/exporting";
// Create Annotatoram5plugins_exporting.Annotator.new(root, { // ... config if applicable});<!-- Load Annotator --><script src="plugins/exporting.js"></script>
<script>// Create Annotatoram5plugins_exporting.Annotator.new(root, { // ... config if applicable});</script>Inheritance
Annotator extends Entity.
Annotator is not extended by any other symbol.
Settings
Set these settings on a Annotator object using its set() and setAll() methods. Read about settings concept.
Defaults are the ones Annotator gets from its own code and the default themes. Inherited settings whose default differs here are listed with its own. Theme rules for a specific context, such as labels of an X axis, can set other values there.
annotationsType
ArraySince 5.25.0The annotations. Setting it draws them, e.g. to restore annotations saved earlier. It is updated when annotation mode closes.
Type
ArrayDefault[ "pin", "undo", "redo", "delete", "clear", "layout", "done" ]Since 5.25.0Buttons in the toolbar besides the tools, in their usual places:
"pin"- pins new annotations to the chart or to the screen."undo","redo"."delete"- removes the selected annotation."clear"- removes all annotations, once confirmed."layout"- lays the toolbar out in rows or in a column."done"- closes annotation mode, keeping the changes."cancel"- closes annotation mode, dropping the changes.
captionTextType
undefined|stringDefaultroot.language.translateAny("Text")Since 5.25.0Text of a new caption.
colorsType
ArrayDefault computed at runtimeSince 5.25.0Colors offered in the toolbar.
defaultTextType
undefined|stringDefaultroot.language.translateAny("Your text here")Since 5.25.0Text of a new text or callout.
disableRotationType
undefined|false|trueDefaultfalseSince 5.25.0Hides the grip that rotates an annotation.
escapeActionType
"save"|"cancel"|"none"Default"save"Since 5.25.0What ESC does in annotation mode, once nothing is selected:
"save"- closes it, keeping the changes."cancel"- closes it, dropping the changes."none"- nothing.
fillType
ColorDefaultroot.interfaceColors.get("background")Since 5.25.0Fill color of new ellipses that are filled and of callouts. The chart's background color by default.
fontFamiliesType
ArrayDefault[ "Helvetica, Arial, sans-serif", "Times, \"Times New Roman\", serif", "Courier, \"Courier New\", monospace", "cursive", "fantasy" ]Since 5.25.0Font families offered in the toolbar.
fontFamilyType
undefined|stringSince 5.25.0Font family of new annotations. The chart's if not set.
fontSizeType
undefined|numberDefault16Since 5.25.0Font size of new annotations.
fontSizesType
ArrayDefault[ 12, 16, 20, 28, 40 ]Since 5.25.0Font sizes offered in the toolbar.
highlightColorType
ColorDefaultam5.color(0xFFFF00)Since 5.25.0Color of new highlights.
highlightOpacityType
undefined|numberDefault0.5Since 5.25.0Opacity of new highlights.
iconsType
ArraySince 5.25.0Icons the icon tool offers. The stock chart's arrows and icons if not set.
layerType
undefined|numberDefault1000Layer the annotations are drawn on, above the chart.
markerSettingsType
undefined|objectSince 5.7.4Deprecated Use the Annotator's own settings
Settings of marker.js 2, which earlier versions used. Those that have an equivalent are applied, e.g.
defaultColorSetascolorsanddefaultStrokeWidthasstrokeWidth.markerStateType
anyDeprecated Use
annotationsAnnotations in the format of marker.js 2, which earlier versions used.
Setting it draws them. When annotation mode closes, the annotations are also written here in that format, so setups that save it keep working.
Use
annotationsinstead: only it keeps what annotations are pinned to.markerStyleSettingsType
undefined|objectSince 5.7.5Deprecated Use a theme
Toolbar styles of marker.js 2, which earlier versions used. Colors of the toolbar and toolbox are applied.
opacityStepsType
ArrayDefault[ 0.1, 0.25, 0.5, 0.75, 1 ]Since 5.25.0Opacities offered in the toolbar.
pinToType
"chart"|"screen"Default"chart"Since 5.25.0What new annotations are pinned to:
"chart"- what is under them: values of an XY chart's axes, a place on a map, a pie slice, or a hierarchy or flow node. They then move, resize and zoom with it. Where there is nothing to pin to, they stay where they are on the chart's area."screen"- where they are on the chart's area.
The user can switch it in the toolbar.
strokeType
ColorDefaultam5.color(0xEF4444)Since 5.25.0Line color of new annotations.
strokeDasharrayType
ArraySince 5.25.0Dash pattern of new annotations.
strokeDasharraysType
ArrayDefault[ [], [ 3, 3 ], [ 12, 3 ], [ 9, 6, 3, 6 ] ]Since 5.25.0Dash patterns offered in the toolbar. An empty one is a solid line.
strokeWidthType
undefined|numberDefault3Since 5.25.0Line width of new annotations.
strokeWidthsType
ArrayDefault[ 1, 2, 3, 5, 10 ]Since 5.25.0Line widths offered in the toolbar.
textColorType
ColorDefaultam5.color(0xEF4444)Since 5.25.0Text color of new annotations.
toolbarLayoutType
"horizontal"|"vertical"|"auto"Default"auto"Since 5.25.0How the toolbar is laid out when annotation mode opens: in rows along the chart's top, or in a column by its left edge.
"auto"picks a column if the chart is taller than it is wide, and rows otherwise.The user can switch it, move the toolbar by its grip, and collapse it by clicking the grip.
toolsType
ArrayDefault[ "rectangle", "ellipse", "highlight", "cover", "line", "arrow", "curve", "measure", "polyline", "freehand", "text", "callout", "caption", "icon" ]Since 5.25.0Tools in the toolbar, in this order.
9 inherited items
animationsType
ArrayInherited fromIEntitySettingsSince 5.20.8Animations the element plays on its own, described as data - so they can be set from a JSON config and saved with it.
Each one animates a setting of the element (or, with
target: "dataItem", a value of its data item - a map point'spositionOnLine, say). They start when the setting is applied, restart when it changes, and stop when the element is disposed. A saved config keeps what was configured, never a value caught half way through an animation.sprite.set("animations", [ { key: "rotation", to: 360, duration: 4000, loops: 0 }, { key: "scale", from: 1, to: 1.3, duration: 800, loops: 0, yoyo: true, easing: "sine" } ]);idType
undefined|stringInherited fromIEntitySettingsA unique ID for looking the element up in
root.entitiesById. Setting an ID that another element already has throws an error.ignoreThemesType
undefined|false|trueDefaultfalseInherited fromIEntitySettingsSince 5.15.6Ignores themes: no theme rule applies to the element, not even one of the default theme.
stateAnimationDurationType
undefined|numberDefault0Inherited fromIEntitySettingsHow long, in milliseconds, a switch from one state to another animates.
0switches at once.stateAnimationEasingType
$ease.EasingDefaultam5.ease.out(am5.ease.cubic)Inherited fromIEntitySettingsEasing of the animated switch from one state to another.
themesType
ArrayInherited fromIEntitySettingsThemes applied to the element and everything inside it.
themeTagsType
ArrayDefault[]Inherited fromIEntitySettingsTags that theme rules can target. They also count for the element's children, so a rule can match a child by a tag of its parent.
More info: Themes
themeTagsSelfType
ArrayInherited fromIEntitySettingsTags that theme rules can target, like
themeTags, but only for this element, not its children.More info: Themes
userDataType
anyInherited fromIEntitySettingsAny data of your own to keep with the element.
Private settings
These are read-only settings accessible from a Annotator object using its getPrivate() method. Read about private settings.
isOpenRead onlyType
undefined|false|truetruewhile annotation mode is open.
Properties
annotationsContainerType
ContainerContainer with the annotations.
classNameStaticType
stringDefault"Annotator"classNamesStaticType
ArrayDefaultEntity.classNames.concat([Annotator.className])containerType
ContainerLayer container with the annotations, and the toolbar while annotation mode is open.
7 inherited items
adaptersType
AdaptersDefaultnew Adapters(this)Inherited fromEntityenableDisposeType
booleanDefaulttrueInherited fromSettingsSet to
falseto makedispose()do nothing.eventsType
EventDispatcherDefaultthis._createEvents()Inherited fromEntityrootType
RootInherited fromEntitySince 5.0.6The
Rootthe object belongs to.statestemplateType
Template|undefinedInherited fromEntityA
Templateapplied to the object. Its settings apply where the object has none set of its own.uidType
numberDefault++counterInherited fromSettingsA unique number, given to each object as it is created.
Methods
cancel()Returns
PromiseCloses annotation mode, discarding the changes made since it opened.
clear()Returns
voidRemoves all annotations.
close()Returns
PromiseCloses annotation mode, keeping the changes. The annotations stay on the chart.
getMarkerArea()Returns
PromiseDeprecated Use the Annotator's own methods, settings and events
The earlier versions returned the marker.js
MarkerAreahere. This returns a stand-in with its most used members, which warn that they are deprecated and do what they can.isOpen()Returns
booleanSince 5.25.0Whether annotation mode is open.
open()Returns
PromiseOpens annotation mode: shows the toolbar, and stops interaction with the chart until annotation mode is closed.
toggle()Returns
PromiseOpens annotation mode, or closes it, keeping the changes, if it is open.
22 inherited items
animate(options:AnimationOptions)Returns
AnimationInherited fromSettingsAnimates a setting from its current value (or
from) toto. The setting jumps tofromat once. Withduration0, or no value to start from, it is set totoat once and the returned animation is already stopped.More info: Animations: animating settings
dispose()Returns
voidInherited fromSettingsDisposes the object, freeing everything it holds. A disposed object can't be used again.
get(key:Key,
fallback:F)Returns
NonNullable|FInherited fromEntityReturns the value of setting
key, run through any adapters, orfallbackif it is not set.More info: Settings
has(key:Key)Returns
booleanInherited fromSettingsReturns
trueif settingkeyis set.More info: Settings
isDisposed()Returns
booleanInherited fromSettingsReturns
trueif the object has been disposed.isType(type:string)Returns
thisInherited fromEntityReturns
trueif the object is of classtypeor extends it.new(root:Root,
settings:ITSettings,
template?:Template)StaticReturns
TInherited fromEntityCreates an instance of the class. Use it instead of
new Class().More info: Getting started: new element syntax
off(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsSince 5.9.2Removes a callback added with
on(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
offDebounced(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsRemoves a callback added with
onDebounced(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
offDebouncedPrivate(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsRemoves a callback added with
onPrivateDebounced(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
offPrivate(key:Key,
callback?:undefined| (value:[""], target:this, key:Key) =>void)Returns
voidInherited fromSettingsSince 5.9.2Removes a callback added with
onPrivate(). Withoutcallback, removes all of them forkey.More info: Events: settings value change
on(key:Key,
callback: (value:[""], target:this, key:Key) =>void)Returns
IDisposerInherited fromSettingsCalls
callbackeach time the value of settingkeychanges or is removed. Setting the same value again does not call it.More info: Events: settings value change
once(key:Key,
callback: (value:[""], target:this, key:Key) =>void)Returns
IDisposerInherited fromSettingsSince 5.20.4Like
on(), but the callback is removed after it is called once.More info: Events: settings value change
onceDebounced(key:Key,
callback: (value:[""], target:this, key:Key) =>void,
debounceDelay:number)Returns
IDisposerInherited fromSettingsSince 5.20.4Like
onDebounced(), but the callback is removed after it is called once.More info: Events: settings value change
onDebounced(key:Key,
callback: (value:[""], target:this, key:Key) =>void,
debounceDelay:number)Returns
IDisposerInherited fromSettingsLike
on(), but waits until settingkeyhas not changed fordebounceDelaymilliseconds, then callscallbackonce with the latest value.More info: Events: settings value change
onPrivate(key:Key,
callback: (value:[""], target:this, key:Key) =>void)Returns
IDisposerInherited fromSettingsCalls
callbackeach time the value of private settingkeychanges.More info: Events: settings value change
onPrivateDebounced(key:Key,
callback: (value:[""], target:this, key:Key) =>void,
debounceDelay:number)Returns
IDisposerInherited fromSettingsLike
onPrivate(), but waits until private settingkeyhas not changed fordebounceDelaymilliseconds, then callscallbackonce with the latest value.More info: Events: settings value change
remove(key:Key)Returns
voidInherited fromEntityRemoves the value set for setting
key. The setting goes back to the value from a theme or template, if one has it.More info: Settings
removeAll()Returns
voidInherited fromSettingsRemoves all settings, as
remove()does for each one.More info: Settings
set(key:Key,
value:Value)Returns
ValueInherited fromEntitySets setting
keytovalueand returnsvalue. A value set this way overrides themes and templates, and stops any animation of the setting.More info: Settings
setAll(settings:Partial)Returns
voidInherited fromSettingsSets several settings at once, from an object of key-value pairs.
More info: Settings
setTimeout(fn: () =>void,
delay:number)Returns
IDisposerInherited fromEntityCalls
fnafterdelaymilliseconds, unless the object is disposed first. Disposing the returned disposer cancels it.
Events
Add event handlers to Annotator object using its events.on() method. Read about adding event handlers.
annotationschangedParam { type:
"annotationschanged", target:Annotator}Since 5.25.0The user changed the annotations.
closedParam { type:
"closed", target:Annotator, cancelled:boolean}Since 5.25.0Annotation mode closed.
cancelledistrueif the changes were discarded.openedParam { type:
"opened", target:Annotator}Since 5.25.0Annotation mode opened.