Guides
Annotations
Declarative overlays on options.annotations: lineX, lineY, bandX, point, and text. Optional createAnnotationAuthoring adds right-click create/edit, drag, undo/redo, and JSON export.
Types
Each entry is an object with a type field. Set layer to 'belowSeries' or 'aboveSeries'. Use a stable id when you patch annotations from app state.
lineY: horizontal line aty; optionallabel(textortemplate)lineX: vertical line atx; optionallabelbandX: filled x-range viafrom/to(order free); no label fieldpoint: marker at(x, y)with optionalmarkerandlabeltext: string atpositionindataorplotspace (plot is 0–1 normalized)
Interactive annotation playground
Seed layers come from the toggles below. On the chart,
right-click to add a vertical/horizontal line or text note,
drag existing annotations to reposition them, and
right-click an annotation to edit or delete
(createAnnotationAuthoring).
Use Undo / Redo / Export JSON in the bar under the chart.
Recipes
Horizontal threshold
{
type: 'lineY',
y: 0.35,
layer: 'belowSeries',
style: { color: '#D4A520', lineWidth: 2, lineDash: [8, 6], opacity: 0.95 },
label: { template: 'max y={y}', decimals: 2 },
}
Vertical event marker
{
type: 'lineX',
x: eventTimestamp,
layer: 'belowSeries',
style: { color: '#6BCB77', lineWidth: 2, opacity: 0.9 },
label: { text: 'deploy' },
}
Highlighted region
bandX fills a vertical window. It has no label field; pair with a text annotation for captions. from/to order does not matter.
{
type: 'bandX',
from: outageStart,
to: outageEnd,
layer: 'belowSeries',
style: { color: '#E05A8C', opacity: 0.14 },
},
{
type: 'text',
layer: 'aboveSeries',
position: { space: 'data', x: outageStart, y: 0.9 },
text: 'regime',
style: { color: '#E05A8C', opacity: 0.95 },
}
Peak marker
{
type: 'point',
x: maxX,
y: maxY,
layer: 'aboveSeries',
marker: { symbol: 'circle', size: 9, style: { color: '#E05A8C' } },
label: { template: 'peak={y}', decimals: 2 },
}
Plot-space text
Use position.space: 'plot' for labels pinned in the plot (0–1 normalized). Data-space text tracks pan/zoom with the series.
{
type: 'text',
position: { space: 'plot', x: 0.04, y: 0.08 },
text: 'note',
layer: 'aboveSeries',
style: { color: '#6BCB77', opacity: 0.95 },
}
Interactive authoring
createAnnotationAuthoring mounts context-menu create/edit, drag, undo/redo, and JSON export on an existing chart. Dispose the authoring helper before the chart.
import { ChartGPU, createAnnotationAuthoring } from '@chartgpu/chartgpu';
const chart = await ChartGPU.create(container, {
series: [{ type: 'line', data }],
annotations: [/* optional seed */],
});
const authoring = createAnnotationAuthoring(container, chart, {
enableContextMenu: true,
});
// authoring.addVerticalLine(x);
// authoring.exportJSON(); authoring.undo(); authoring.redo();
// cleanup: authoring.dispose(); chart.dispose();
Full demo: annotation-authoring example.
Performance tips
- Keep visible annotations under ~30; batch changes in one
setOption. - Use
belowSeriesfor bands and reference lines;aboveSeriesfor peaks and HUD. - Prefer stable
idfields when you patch annotations from your app state.
Related
- Annotations API — types, authoring, hit-test
- Theming — palette and chrome colors for labels
- Multi-chart dashboards — events on live series
- Charting guide — series + interaction overview