Skip to content

Class: Plot ​

Defined in: plot.ts:434

The imperative core plot. Owns a stack of three canvases (grid / WebGL data / axis overlay), a shared x scale, and one-or-more named y axes.

Constructors ​

Constructor ​

ts
new Plot(container, options?): Plot;

Defined in: plot.ts:519

Parameters ​

ParameterType
containerHTMLElement
optionsPlotOptions

Returns ​

Plot

Accessors ​

context ​

Get Signature ​

ts
get context(): WebGL2RenderingContext;

Defined in: plot.ts:872

The shared WebGL2 context, for constructing custom layers.

Returns ​

WebGL2RenderingContext


element ​

Get Signature ​

ts
get element(): HTMLElement;

Defined in: plot.ts:881

The container this plot renders into (already position: relative), for custom overlays — a chart-specific tooltip, a colorbar, a caption. Append absolutely-positioned children with zIndex >= 3 to sit above the canvases.

Returns ​

HTMLElement

Methods ​

add() ​

ts
add<T>(layer): T;

Defined in: plot.ts:867

Register a layer built outside core (a custom WebGL2 Layer). Use with context to construct the layer against this plot's WebGL2 context.

Type Parameters ​

Type Parameter
T extends Layer

Parameters ​

ParameterType
layerT

Returns ​

T


addAnnotation() ​

ts
addAnnotation(a): () => void;

Defined in: plot.ts:1088

Add a Canvas2D annotation (span / band / box / label) drawn above the data. Returns a disposer that removes just this annotation.

Parameters ​

ParameterType
aAnnotation

Returns ​

() => void


addArea() ​

ts
addArea(opts): AreaLayer;

Defined in: plot.ts:982

Parameters ​

ParameterType
optsAreaOptions

Returns ​

AreaLayer


addBar() ​

ts
addBar(opts): BarLayer;

Defined in: plot.ts:914

Parameters ​

ParameterType
optsBarOptions

Returns ​

BarLayer


addBox() ​

ts
addBox(opts): BoxLayer;

Defined in: plot.ts:990

Parameters ​

ParameterType
optsBoxOptions

Returns ​

BoxLayer


addCandlestick() ​

ts
addCandlestick(opts): CandlestickLayer;

Defined in: plot.ts:1014

Parameters ​

ParameterType
optsCandlestickOptions

Returns ​

CandlestickLayer


addContour() ​

ts
addContour(opts): ContourLayer;

Defined in: plot.ts:998

Parameters ​

ParameterType
optsContourOptions

Returns ​

ContourLayer


addDrawing() ​

ts
addDrawing(a): void;

Defined in: plot.ts:1132

Add a drawing programmatically (same shapes the tools produce).

Parameters ​

ParameterType
aAnnotation

Returns ​

void


addErrorBar() ​

ts
addErrorBar(opts): ErrorBarLayer;

Defined in: plot.ts:1002

Parameters ​

ParameterType
optsErrorBarOptions

Returns ​

ErrorBarLayer


addGraph() ​

ts
addGraph(opts): GraphLayer;

Defined in: plot.ts:1050

A node-link graph. Provide node x/y, or omit them (with nodes, or let the count be inferred from the edges) to auto-place with a force-directed layout.

Parameters ​

ParameterType
optsGraphInput

Returns ​

GraphLayer


addGroupedBars() ​

ts
addGroupedBars(opts): BarLayer[];

Defined in: plot.ts:922

Grouped (clustered) bars: one BarLayer per series, each shifted within its category group so the bars sit side by side. Returns the layers in order.

Parameters ​

ParameterType
optsGroupedBarOptions

Returns ​

BarLayer[]


addHeatmap() ​

ts
addHeatmap(opts): HeatmapLayer;

Defined in: plot.ts:986

Parameters ​

ParameterType
optsHeatmapOptions

Returns ​

HeatmapLayer


addHeatmapSpectrogram() ​

ts
addHeatmapSpectrogram(signal, opts?): HeatmapLayer;

Defined in: plot.ts:1343

Compute an STFT of signal and render it as a heatmap (time × frequency).

Parameters ​

ParameterType
signalArrayLike<number>
opts{ colormap?: ColormapSpec; fftSize?: number; hop?: number; sampleRate?: number; }
opts.colormap?ColormapSpec
opts.fftSize?number
opts.hop?number
opts.sampleRate?number

Returns ​

HeatmapLayer


addHexbin() ​

ts
addHexbin(opts): HexbinLayer;

Defined in: plot.ts:994

Parameters ​

ParameterType
optsHexbinOptions

Returns ​

HexbinLayer


addHistogram() ​

ts
addHistogram(values, opts?): BarLayer;

Defined in: plot.ts:1360

Bin raw values and render a histogram as bars.

Parameters ​

ParameterType
valuesArrayLike<number>
opts{ bins?: number; color?: string; name?: string; range?: [number, number]; yAxis?: string; }
opts.bins?number
opts.color?string
opts.name?string
opts.range?[number, number]
opts.yAxis?string

Returns ​

BarLayer


addImage() ​

ts
addImage(opts): ImageLayer;

Defined in: plot.ts:1034

An RGBA image / URL drawn over a data-space extent. URLs redraw on load.

Parameters ​

ParameterType
optsImageOptions

Returns ​

ImageLayer


addLine() ​

ts
addLine(opts): LineLayer;

Defined in: plot.ts:906

Parameters ​

ParameterType
optsLineOptions

Returns ​

LineLayer


addOhlc() ​

ts
addOhlc(opts): OhlcLayer;

Defined in: plot.ts:1019

An OHLC bar chart (low→high line with open/close ticks). Streams like candlesticks.

Parameters ​

ParameterType
optsOhlcOptions

Returns ​

OhlcLayer


addPatches() ​

ts
addPatches(opts): PatchesLayer;

Defined in: plot.ts:1024

Filled polygons (choropleth-capable). Rings are triangulated with earcut.

Parameters ​

ParameterType
optsPatchesOptions

Returns ​

PatchesLayer


addPie() ​

ts
addPie(opts): PieLayer;

Defined in: plot.ts:1029

A pie / donut chart. Set equalAspect: true on the plot so it stays circular.

Parameters ​

ParameterType
optsPieOptions

Returns ​

PieLayer


addQuiver() ​

ts
addQuiver(opts): QuiverLayer;

Defined in: plot.ts:1010

Parameters ​

ParameterType
optsQuiverOptions

Returns ​

QuiverLayer


addScatter() ​

ts
addScatter(opts): ScatterLayer;

Defined in: plot.ts:910

Parameters ​

ParameterType
optsScatterOptions

Returns ​

ScatterLayer


addStackedArea() ​

ts
addStackedArea(opts): AreaLayer[];

Defined in: plot.ts:1065

Stacked area: each series is filled from the running cumulative total of the ones before it. Returns the layers bottom-to-top.

Parameters ​

ParameterType
optsStackedAreaOptions

Returns ​

AreaLayer[]


addStackedBars() ​

ts
addStackedBars(opts): BarLayer[];

Defined in: plot.ts:954

Stacked bars: each series is drawn from the running cumulative total of the ones before it, so they stack. Returns the layers bottom-to-top.

Parameters ​

ParameterType
optsStackedBarOptions

Returns ​

BarLayer[]


addStem() ​

ts
addStem(opts): StemLayer;

Defined in: plot.ts:1006

Parameters ​

ParameterType
optsStemOptions

Returns ​

StemLayer


addYAxis() ​

ts
addYAxis(id, opts?): void;

Defined in: plot.ts:1384

Register an additional named y axis. Series opt in via addLine({ yAxis }).

Parameters ​

ParameterType
idstring
optsYAxisOptions

Returns ​

void


autoscale() ​

ts
autoscale(): void;

Defined in: plot.ts:1611

Re-fit auto axes to the data: x over all series, each y axis over its own series.

Returns ​

void


clearAnnotations() ​

ts
clearAnnotations(): void;

Defined in: plot.ts:1102

Remove all annotations.

Returns ​

void


clearDrawings() ​

ts
clearDrawings(): void;

Defined in: plot.ts:1143

Remove every user drawing.

Returns ​

void


copyToClipboard() ​

ts
copyToClipboard(opts?): Promise<void>;

Defined in: plot.ts:1606

Copy the current view to the clipboard as a PNG. Throws if the browser can't.

Parameters ​

ParameterType
optsExportOptions

Returns ​

Promise<void>


dataAt() ​

ts
dataAt(clientX, clientY): 
  | {
  x: number;
  y: number;
}
  | null;

Defined in: plot.ts:890

Convert a client (screen) coordinate to data space — the shared x and the primary y. Returns null if the point is outside the plot region. Useful for custom hit-testing (e.g. map feature picking on click).

Parameters ​

ParameterType
clientXnumber
clientYnumber

Returns ​

| { x: number; y: number; } | null


describe() ​

ts
describe(): string;

Defined in: plot.ts:850

A one-line text summary of the chart (title + series), for a11y / tooltips.

Returns ​

string


destroy() ​

ts
destroy(): void;

Defined in: plot.ts:1641

Returns ​

void


downloadImage() ​

ts
downloadImage(
   filename?, 
   type?, 
opts?): Promise<void>;

Defined in: plot.ts:1601

Download the current view as an image (PNG by default).

Parameters ​

ParameterTypeDefault value
filenamestring"chart.png"
typestring"image/png"
optsExportOptions{}

Returns ​

Promise<void>


getDrawings() ​

ts
getDrawings(): Annotation[];

Defined in: plot.ts:1138

All user drawings (trendlines, fib levels, …).

Returns ​

Annotation[]


getDrawTool() ​

ts
getDrawTool(): DrawTool | null;

Defined in: plot.ts:1121

The active drawing tool, or null.

Returns ​

DrawTool | null


getMode() ​

ts
getMode(): InteractionMode;

Defined in: plot.ts:1533

Returns ​

InteractionMode


hasYAxis() ​

ts
hasYAxis(id): boolean;

Defined in: plot.ts:1403

Whether a y axis with this id exists (the primary is always "y").

Parameters ​

ParameterType
idstring

Returns ​

boolean


home() ​

ts
home(): void;

Defined in: plot.ts:1542

Reset to the home view: explicit domains restored, auto axes re-fit to data.

Returns ​

void


isEqualAspect() ​

ts
isEqualAspect(): boolean;

Defined in: plot.ts:1466

Whether setEqualAspect is currently on.

Returns ​

boolean


isLayerVisible() ​

ts
isLayerVisible(layer): boolean;

Defined in: plot.ts:1895

Whether a layer is currently drawn (hidden layers also drop out of autoscale).

Parameters ​

ParameterType
layerLayer

Returns ​

boolean


isOnScreen() ​

ts
isOnScreen(): boolean;

Defined in: plot.ts:1461

Whether this chart is currently on screen (plus a small margin), as PlotOptions.offscreenCulling judges it.

Photon already skips its own drawing while a chart is out of view, but it cannot skip the work that produces the data — a streaming app should check this before regenerating a series and calling setData, which uploads to the GPU whether or not anyone is looking. Always true when culling is off.

Returns ​

boolean


onCursorMove() ​

ts
onCursorMove(cb): () => void;

Defined in: plot.ts:1505

Subscribe to the hover cursor's data-space x (or null when it leaves the plot). Returns an unsubscribe function. Used to share a crosshair across panes.

Parameters ​

ParameterType
cb(dataX) => void

Returns ​

() => void


onDrawToolChange() ​

ts
onDrawToolChange(cb): () => void;

Defined in: plot.ts:1126

Subscribe to draw-tool changes (used by the toolbar). Returns an unsubscribe fn.

Parameters ​

ParameterType
cb(t) => void

Returns ​

() => void


onModeChange() ​

ts
onModeChange(cb): void;

Defined in: plot.ts:1537

Parameters ​

ParameterType
cb(mode) => void

Returns ​

void


onViewChange() ​

ts
onViewChange(cb): () => void;

Defined in: plot.ts:1487

Subscribe to x-domain changes (pan / zoom / home / setView). Fires once per frame after the domain settles. Returns an unsubscribe function. See linkX.

Parameters ​

ParameterType
cb(x) => void

Returns ​

() => void


onVisibilityChange() ​

ts
onVisibilityChange(cb): () => void;

Defined in: plot.ts:1917

Subscribe to show/hide changes (legend clicks included). Returns an unsubscribe fn.

Parameters ​

ParameterType
cb(layer, visible) => void

Returns ​

() => void


onYViewChange() ​

ts
onYViewChange(cb): () => void;

Defined in: plot.ts:1496

Subscribe to primary-y domain changes, the y counterpart of onViewChange. Returns an unsubscribe function. See linkY.

Parameters ​

ParameterType
cb(y) => void

Returns ​

() => void


removeLayer() ​

ts
removeLayer(layer): void;

Defined in: plot.ts:1414

Parameters ​

ParameterType
layerLayer

Returns ​

void


removeYAxis() ​

ts
removeYAxis(id): void;

Defined in: plot.ts:1408

Remove a secondary y axis. No-op for the primary "y" or an unknown id.

Parameters ​

ParameterType
idstring

Returns ​

void


render() ​

ts
render(): void;

Defined in: plot.ts:1753

Returns ​

void


requestRender() ​

ts
requestRender(): void;

Defined in: plot.ts:1715

Returns ​

void


setAriaLabel() ​

ts
setAriaLabel(text): void;

Defined in: plot.ts:844

Set the chart's accessible label (aria-label). Pass undefined to auto-summarize.

Parameters ​

ParameterType
textstring | undefined

Returns ​

void


setAxis() ​

ts
setAxis(dim, config): void;

Defined in: plot.ts:1426

Configure ticks/format/title for the x axis or a y axis (default primary "y").

Parameters ​

ParameterType
dimstring
configPartial<AxisConfig>

Returns ​

void


setDrawTool() ​

ts
setDrawTool(tool): void;

Defined in: plot.ts:1111

Activate a drawing tool (click-drag on the plot to place), or null to stop drawing.

Parameters ​

ParameterType
toolDrawTool | null

Returns ​

void


setEqualAspect() ​

ts
setEqualAspect(on): void;

Defined in: plot.ts:1443

Keep data-units-per-pixel equal on both axes, so nothing is distorted when the container's aspect changes (the looser axis is expanded to match). Essential for anything whose shape carries meaning — maps, pie charts, schematics.

Parameters ​

ParameterType
onboolean

Returns ​

void


setLayerVisible() ​

ts
setLayerVisible(layer, visible): void;

Defined in: plot.ts:1900

Show or hide a layer, re-fitting the auto axes to what remains visible.

Parameters ​

ParameterType
layerLayer
visibleboolean

Returns ​

void


setLinkedCursor() ​

ts
setLinkedCursor(dataX): void;

Defined in: plot.ts:1511

Draw a linked crosshair at this data-space x (pushed from another pane), or clear it with null.

Parameters ​

ParameterType
dataXnumber | null

Returns ​

void


setMode() ​

ts
setMode(mode): void;

Defined in: plot.ts:1526

Parameters ​

ParameterType
modeInteractionMode

Returns ​

void


setView() ​

ts
setView(view): void;

Defined in: plot.ts:1471

Set (or lock) the visible domain. y targets the primary axis; use yAxes for others.

Parameters ​

ParameterType
view{ x?: Range; y?: Range; yAxes?: Record<string, Range>; }
view.x?Range
view.y?Range
view.yAxes?Record<string, Range>

Returns ​

void


toBlob() ​

ts
toBlob(type?, opts?): Promise<Blob | null>;

Defined in: plot.ts:1596

Export the current view as a Blob (default PNG).

Parameters ​

ParameterTypeDefault value
typestring"image/png"
optsExportOptions{}

Returns ​

Promise<Blob | null>


toDataURL() ​

ts
toDataURL(type?, opts?): string;

Defined in: plot.ts:1591

Export the current view as a data URL (default PNG).

Parameters ​

ParameterTypeDefault value
typestring"image/png"
optsExportOptions{}

Returns ​

string


toggleLayer() ​

ts
toggleLayer(layer): boolean;

Defined in: plot.ts:1910

Flip a layer's visibility. Returns the new state.

Parameters ​

ParameterType
layerLayer

Returns ​

boolean

MIT licensed. WebGL2 required.