Annotator
Annotator lets users draw on a chart: frames, ellipses, highlights, lines, arrows, curves, polylines, freehand lines, text, callouts and captions.
Annotations are drawn as part of the chart, so image and PDF exports include them. They can be pinned to the chart’s data, so they move and zoom with it.
Loading
Section titled “Loading”Annotator comes with the Exporting plugin. If you use other exporting features, there is nothing more to load.
You can import those in your TypeScript / ES6 application as JavaScript modules:
import * as am5plugins_exporting from "@amcharts/amcharts5/plugins/exporting";For vanilla JavaScript applications and web pages, you can use “script” version:
<script src="https://cdn.amcharts.com/lib/5/plugins/exporting.js"></script>The code that draws annotations and the toolbar loads when the annotator first has annotations or opens.
Enabling
Section titled “Enabling”Annotator is instantiated just like any other object in amCharts 5: by calling new() method of its class, passing in root element and settings object.
let annotator = am5plugins_exporting.Annotator.new(root, {});var annotator = am5plugins_exporting.Annotator.new(root, {});Invoking
Section titled “Invoking”Via API
Section titled “Via API”| Method | Comment |
|---|---|
open() |
Opens annotation mode: shows the toolbar, stops interaction with the chart, and hides the export menu and the XY chart cursor. |
close() |
Closes annotation mode, keeping the changes. Annotations stay on the chart. |
toggle() |
Opens annotation mode, or closes it, keeping the changes. |
cancel() |
Closes annotation mode, discarding the changes made since it opened. |
clear() |
Removes all annotations. |
isOpen() |
Returns true while annotation mode is open. |
annotator.open();annotator.open();Via export menu
Section titled “Via export menu”We can add Annotator to export menu by manually inserting it into menu items:
let menuitems = exporting.get("menu").get("items");
menuitems.push({ type: "separator"});
menuitems.push({ type: "custom", label: "Annotate", callback: function() { this.close(); annotator.toggle(); }});var menuitems = exporting.get("menu").get("items");
menuitems.push({ type: "separator"});
menuitems.push({ type: "custom", label: "Annotate", callback: function() { this.close(); annotator.toggle(); }});Example
Section titled “Example”Using the toolbar
Section titled “Using the toolbar”The toolbar starts in rows along the chart’s top, in the colors of the chart’s theme. Drag it by its grip to move it, or click the grip to collapse it to Done and Cancel. It is never larger than the chart: buttons wrap to a new column or row.
Related tools share a button: shapes, lines, drawing and text. A small triangle in the corner marks them. Click the button to use the tool it shows; click it again, or press and hold it, to pick another tool of the group. The Icon tool places arrows, stars, flags and other icons, as in the stock chart.
After the tools come these buttons:
| Button | What it does |
|---|---|
| Pin | Switches between pinning new annotations to the chart and to the screen. With an annotation selected, re-pins it. |
| Undo, Redo | Steps back or forward through the changes. |
| Delete | Removes the selected annotation. |
| Clear all | Removes all annotations, once confirmed in a pop-up. |
| Layout | Switches the toolbar between a column and rows. |
| Done, Cancel | Closes annotation mode, keeping or discarding the changes. Cancel is not shown unless added to buttons. |
Below the tools (beside them, in a column), on a gray background, are the colors, line width, line style, line ends, font, font size, opacity and blur of the selected annotation, or of the next one drawn with the current tool.
To draw a line, click where it starts and click where it ends, or drag. To draw a polyline, click each of its points; right-click or press Enter to end it, or double-click to close it back to its first point.
A drawing tool stays on after drawing: a click on an empty spot unselects what was just drawn, the next one draws again. Clicking another annotation selects it and switches to its tool.
Click an annotation to select it, then drag it to move it, or drag its grips to resize or rotate it. Double-click text, a callout or a caption to edit its text.
| Key | What it does |
|---|---|
Delete |
Removes the selected annotation. |
Enter |
Edits the selected annotation’s text. |
Esc |
Closes a pop-up, or unselects. With nothing selected, closes annotation mode, saving (see escapeAction). |
Ctrl+Z |
Undo. |
Ctrl+Y |
Redo. |
Shift while dragging |
Keeps lines at 45° steps and frames square, and keeps the shape when resizing. Rotation snaps to 15°. |
With the keyboard
Section titled “With the keyboard”When annotation mode opens, focus goes to the toolbar. Tab goes through the toolbar, the style buttons, then the annotations. Pop-ups take focus when they open; Esc closes them and puts focus back on their button.
Enteron a tool’s button adds an annotation of the usual size where the chart was last focused (a column, a slice, a node), or in the middle of the plot area, and focuses it. Text, callouts and captions open their text for typing;TaborEscends it. Freehand lines and polylines are drawn with a pointer.- On a focused annotation, the arrow keys move it, and
Shiftwith the arrow keys moves a line’s end, a frame’s corner or a callout’s tip.Page UpandPage Downturn a shape, a text or an icon by 15 degrees. It is pinned again to what it is on. - The arrow keys on the toolbar’s grip move the toolbar.
On a focused annotation, Esc closes annotation mode (see escapeAction). Done or Esc puts focus back where it was before annotation mode opened.
Known limitation: a pointer moves, resizes and turns annotations only by dragging.
Screen readers
Section titled “Screen readers”Toolbar buttons say whether they are on, and style buttons that open a pop-up say whether it is open.
Outside annotation mode, an annotation with text, or pinned to a slice, node or data item, is read after the chart: its tool, its text, and what it is pinned to, e.g. “Callout: Needs improvement (Czechia)”. Set an annotation’s ariaLabel to say something else, or to describe one that is not read otherwise, such as a frame on an XY chart. Set it to "" to keep an annotation from screen readers.
Pinning annotations
Section titled “Pinning annotations”By default, an annotation is pinned to what is under its middle (a line’s start, a callout’s tip). On a pie, hierarchy, flow, Venn, radar or timeline chart, if that is not on a slice, node or column, it is pinned to the one whose center is nearest, or to the nearest data point. Moving or resizing an annotation pins it again.
What annotations are pinned to:
| Chart | Pinned to | Moves with |
|---|---|---|
| XY chart (including stock and Gantt) | Values of the X and Y axes | Zoom, scroll, resize |
| Radar and timeline | A column or a data point | Its position |
| Map | Longitude and latitude | Zoom, pan, rotation |
| Pie and other percent charts | A slice | The slice’s size and position |
| Hierarchy (treemap, sunburst, pack, …) | A node | The node’s size and position, drill-down |
| Flow (Sankey, chord, arc diagram) | A node | The node’s size and position |
| Venn | A circle or an overlap | Its size and position |
| Word cloud | A word | The word’s size and position |
Shapes pinned to an XY chart or a map stretch when zoomed, and are clipped to its plot area. Text and callout boxes keep their size and move with their point.
A line’s or curve’s end, and each point of a polyline, is pinned to what it is on, if that is something else: a line or arrow can connect two nodes, two slices or two places on a map, and stays connected as they move. A line’s end on a round node (force-directed, pack) slides round it, keeping its distance from the center, so it always faces the line’s other end.
When the item an annotation is pinned to is hidden, so is the annotation. Where there is nothing to pin to, an annotation stays where it is on the chart’s area.
To pin new annotations to the screen by default, set pinTo to "screen":
let annotator = am5plugins_exporting.Annotator.new(root, { pinTo: "screen"});var annotator = am5plugins_exporting.Annotator.new(root, { pinTo: "screen"});Columns and data points of radar and timeline charts are found by the index of their series and data item. Pie slices, Venn circles and words are found by category, and flow nodes by ID. Hierarchy nodes are found by ID if the chart sets idField, and otherwise by their place in the hierarchy.
Configuring
Section titled “Configuring”| Setting | Default | Comment |
|---|---|---|
tools |
All | Tools in the toolbar, in this order: "rectangle", "ellipse", "highlight", "cover", "line", "arrow", "curve", "measure", "polyline", "freehand", "text", "callout", "caption", "icon". |
pinTo |
"chart" |
What new annotations are pinned to: "chart" or "screen". |
toolbarLayout |
"auto" |
How the toolbar is laid out when annotation mode opens: "horizontal", "vertical", or "auto" (vertical if the chart is taller than it is wide). |
buttons |
All but "cancel" |
Buttons besides the tools: "pin", "undo", "redo", "delete", "clear", "layout", "done", "cancel". |
escapeAction |
"save" |
What Esc does with nothing selected: "save" closes annotation mode keeping the changes, "cancel" drops them, "none" does nothing. |
icons |
The stock chart’s | Icons the Icon tool offers: objects with svgPath (in a 50 by 50 box), and optionally centerX and centerY (0-1: the point placed on the clicked spot) and fillDisabled. |
colors |
Colors offered in the toolbar. | |
stroke |
red | Line color of new annotations. |
fill |
The chart’s background color | Fill color of new callouts. |
textColor |
red | Text color of new annotations. |
highlightColor |
yellow | Color of new highlights. |
highlightOpacity |
0.5 |
Opacity of new highlights. |
strokeWidth |
3 |
Line width of new annotations. |
strokeWidths |
[1, 2, 3, 5, 10] |
Line widths offered in the toolbar. |
strokeDasharray |
Dash pattern of new annotations. | |
strokeDasharrays |
[[], [3, 3], [12, 3], [9, 6, 3, 6]] |
Dash patterns offered in the toolbar. |
opacitySteps |
[0.1, 0.25, 0.5, 0.75, 1] |
Opacities offered in the toolbar. |
fontFamily |
The chart’s | Font of new annotations. |
fontFamilies |
Fonts offered in the toolbar. | |
fontSize |
16 |
Font size of new annotations. |
fontSizes |
[12, 16, 20, 28, 40] |
Font sizes offered in the toolbar. |
defaultText |
"Your text here" |
Text of a new text or callout. |
captionText |
"Text" |
Text of a new caption. |
disableRotation |
false |
Hides the grip that rotates an annotation. |
layer |
1000 |
Layer the annotations are drawn on. |
let annotator = am5plugins_exporting.Annotator.new(root, { tools: ["rectangle", "arrow", "text", "callout"], colors: [am5.color(0xff0000), am5.color(0x00aa00), am5.color(0x0000ff)], stroke: am5.color(0x0000ff), strokeWidth: 2});var annotator = am5plugins_exporting.Annotator.new(root, { tools: ["rectangle", "arrow", "text", "callout"], colors: [am5.color(0xff0000), am5.color(0x00aa00), am5.color(0x0000ff)], stroke: am5.color(0x0000ff), strokeWidth: 2});Saving and restoring annotations
Section titled “Saving and restoring annotations”The annotations are in the annotations setting. It is updated when annotation mode closes, and can be saved as JSON:
annotator.events.on("closed", function(ev) { if (!ev.cancelled) { localStorage.setItem("annotations", JSON.stringify(annotator.get("annotations"))); }});annotator.events.on("closed", function(ev) { if (!ev.cancelled) { localStorage.setItem("annotations", JSON.stringify(annotator.get("annotations"))); }});To restore them, set annotations when creating the annotator, or later with set():
let annotator = am5plugins_exporting.Annotator.new(root, { annotations: JSON.parse(localStorage.getItem("annotations") || "[]")});var annotator = am5plugins_exporting.Annotator.new(root, { annotations: JSON.parse(localStorage.getItem("annotations") || "[]")});Annotation format
Section titled “Annotation format”Annotations are plain objects, so they can also be made in code. This one frames January 5 to 7 and values 30 to 70 of an XY chart:
annotator.set("annotations", [{ shape: "rectangle", pin: { kind: "xy", target: 0, xAxis: 0, yAxis: 0 }, points: [ { x: new Date(2026, 0, 5).getTime(), y: 30 }, { x: new Date(2026, 0, 7).getTime(), y: 70 } ], stroke: "#ff0000", strokeWidth: 2}]);annotator.set("annotations", [{ shape: "rectangle", pin: { kind: "xy", target: 0, xAxis: 0, yAxis: 0 }, points: [ { x: new Date(2026, 0, 5).getTime(), y: 30 }, { x: new Date(2026, 0, 7).getTime(), y: 70 } ], stroke: "#ff0000", strokeWidth: 2}]);| Key | Comment |
|---|---|
shape |
"rectangle", "ellipse", "line", "curve", "polyline", "freehand", "text", "callout" or "caption". |
points |
Two corners for frames, ellipses and captions; start and end for lines; start, end and control point for curves; every point of a polyline or a freehand line; the center of text; the point a callout points at and the center of its box. |
pin |
What the annotation is pinned to. Without it, x and y of points are shares of the chart’s width and height (0-1). |
points[].pin |
What a point is pinned to, if not the annotation’s pin, e.g. a line’s end on another node. Its x and y are relative to it. |
stroke, strokeWidth, strokeDasharray |
Line color (a CSS color), width and dash pattern. |
fill, fillOpacity |
Fill color and its opacity. |
opacity, rotation |
Opacity of the whole annotation, and its rotation in degrees. |
blur |
Set on a rectangle (the Cover tool), blurs what is under it: from 0 to 1. Its fill, if any, tints the blur. |
closed |
A polyline goes back from its last point to its first. |
ariaLabel |
What screen readers say for it (see Screen readers). "" keeps it from them. |
icon |
SVG path of an icon (the Icon tool), drawn in a 50 by 50 box and fitted in the annotation’s. |
startCap, endCap |
Line ends: "none", "arrow" or "tick". |
text, textColor, fontFamily, fontSize, width |
Text, and the width it wraps to. |
pin has these keys:
| Key | Comment |
|---|---|
kind |
"xy": points are axis values (a timestamp on a date axis, a category on a category axis). "geo": longitude and latitude. "item": shares of the item’s width and height, of a slice’s arc and thickness, or pixels from a data point; for a line’s end on a round node, its distance from the center in radii and an angle. |
target |
The chart or series: its id setting, or its index among the charts and series annotations can be pinned to, in the order they are drawn. |
xAxis, yAxis |
For "xy": the axes, as their id or index. |
item |
For "item": the slice’s category, the node’s ID or index path, or [series index, data item index]. |
With the chart serializer
Section titled “With the chart serializer”ChartSerializer saves an annotator’s annotations and settings with the chart, and JsonParser restores them. Only annotations pinned to the serialized chart, or to the screen, are saved. If the exporting plugin isn’t loaded when the config is parsed, the chart is built without them.
Events
Section titled “Events”| Event | Comment |
|---|---|
opened |
Annotation mode opened. |
closed |
Annotation mode closed. cancelled is true if the changes were discarded. |
annotationschanged |
The user changed the annotations. |
Upgrading from earlier versions
Section titled “Upgrading from earlier versions”Before version 5.25.0, Annotator used the marker.js 2 library. Code written for it keeps working:
markerStatestill restores saved annotations, pinned to the screen. When annotation mode closes, the annotations are also written to it in that format.markerSettingskeys that have an equivalent are applied, e.g.defaultColorSetascolors,defaultColorasstrokeandtextColor,defaultStrokeWidthasstrokeWidth.markerStyleSettingstoolbar colors are applied.getMarkerArea()returns a stand-in with the most used members:settings,uiStyleSettings,isOpen,availableMarkerTypes,show(),close(),restoreState(),getState(), and therenderandcloseevents.
Anything else logs a console warning. Use annotations to save new annotations: only it keeps what they are pinned to.
The toolbar has no Cancel (close without saving) button by default, and Esc saves. To get marker.js’s behavior back, add "cancel" to buttons and set escapeAction to "cancel".