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
new Plot(container, options?): Plot;Defined in: plot.ts:519
Parameters
| Parameter | Type |
|---|---|
container | HTMLElement |
options | PlotOptions |
Returns
Plot
Accessors
context
Get Signature
get context(): WebGL2RenderingContext;Defined in: plot.ts:872
The shared WebGL2 context, for constructing custom layers.
Returns
WebGL2RenderingContext
element
Get Signature
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()
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
| Parameter | Type |
|---|---|
layer | T |
Returns
T
addAnnotation()
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
| Parameter | Type |
|---|---|
a | Annotation |
Returns
() => void
addArea()
addArea(opts): AreaLayer;Defined in: plot.ts:982
Parameters
| Parameter | Type |
|---|---|
opts | AreaOptions |
Returns
addBar()
addBar(opts): BarLayer;Defined in: plot.ts:914
Parameters
| Parameter | Type |
|---|---|
opts | BarOptions |
Returns
addBox()
addBox(opts): BoxLayer;Defined in: plot.ts:990
Parameters
| Parameter | Type |
|---|---|
opts | BoxOptions |
Returns
addCandlestick()
addCandlestick(opts): CandlestickLayer;Defined in: plot.ts:1014
Parameters
| Parameter | Type |
|---|---|
opts | CandlestickOptions |
Returns
addContour()
addContour(opts): ContourLayer;Defined in: plot.ts:998
Parameters
| Parameter | Type |
|---|---|
opts | ContourOptions |
Returns
addDrawing()
addDrawing(a): void;Defined in: plot.ts:1132
Add a drawing programmatically (same shapes the tools produce).
Parameters
| Parameter | Type |
|---|---|
a | Annotation |
Returns
void
addErrorBar()
addErrorBar(opts): ErrorBarLayer;Defined in: plot.ts:1002
Parameters
| Parameter | Type |
|---|---|
opts | ErrorBarOptions |
Returns
addGraph()
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
| Parameter | Type |
|---|---|
opts | GraphInput |
Returns
addGroupedBars()
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
| Parameter | Type |
|---|---|
opts | GroupedBarOptions |
Returns
BarLayer[]
addHeatmap()
addHeatmap(opts): HeatmapLayer;Defined in: plot.ts:986
Parameters
| Parameter | Type |
|---|---|
opts | HeatmapOptions |
Returns
addHeatmapSpectrogram()
addHeatmapSpectrogram(signal, opts?): HeatmapLayer;Defined in: plot.ts:1343
Compute an STFT of signal and render it as a heatmap (time × frequency).
Parameters
| Parameter | Type |
|---|---|
signal | ArrayLike<number> |
opts | { colormap?: ColormapSpec; fftSize?: number; hop?: number; sampleRate?: number; } |
opts.colormap? | ColormapSpec |
opts.fftSize? | number |
opts.hop? | number |
opts.sampleRate? | number |
Returns
addHexbin()
addHexbin(opts): HexbinLayer;Defined in: plot.ts:994
Parameters
| Parameter | Type |
|---|---|
opts | HexbinOptions |
Returns
addHistogram()
addHistogram(values, opts?): BarLayer;Defined in: plot.ts:1360
Bin raw values and render a histogram as bars.
Parameters
| Parameter | Type |
|---|---|
values | ArrayLike<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
addImage()
addImage(opts): ImageLayer;Defined in: plot.ts:1034
An RGBA image / URL drawn over a data-space extent. URLs redraw on load.
Parameters
| Parameter | Type |
|---|---|
opts | ImageOptions |
Returns
addLine()
addLine(opts): LineLayer;Defined in: plot.ts:906
Parameters
| Parameter | Type |
|---|---|
opts | LineOptions |
Returns
addOhlc()
addOhlc(opts): OhlcLayer;Defined in: plot.ts:1019
An OHLC bar chart (low→high line with open/close ticks). Streams like candlesticks.
Parameters
| Parameter | Type |
|---|---|
opts | OhlcOptions |
Returns
addPatches()
addPatches(opts): PatchesLayer;Defined in: plot.ts:1024
Filled polygons (choropleth-capable). Rings are triangulated with earcut.
Parameters
| Parameter | Type |
|---|---|
opts | PatchesOptions |
Returns
addPie()
addPie(opts): PieLayer;Defined in: plot.ts:1029
A pie / donut chart. Set equalAspect: true on the plot so it stays circular.
Parameters
| Parameter | Type |
|---|---|
opts | PieOptions |
Returns
addQuiver()
addQuiver(opts): QuiverLayer;Defined in: plot.ts:1010
Parameters
| Parameter | Type |
|---|---|
opts | QuiverOptions |
Returns
addScatter()
addScatter(opts): ScatterLayer;Defined in: plot.ts:910
Parameters
| Parameter | Type |
|---|---|
opts | ScatterOptions |
Returns
addStackedArea()
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
| Parameter | Type |
|---|---|
opts | StackedAreaOptions |
Returns
addStackedBars()
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
| Parameter | Type |
|---|---|
opts | StackedBarOptions |
Returns
BarLayer[]
addStem()
addStem(opts): StemLayer;Defined in: plot.ts:1006
Parameters
| Parameter | Type |
|---|---|
opts | StemOptions |
Returns
addYAxis()
addYAxis(id, opts?): void;Defined in: plot.ts:1384
Register an additional named y axis. Series opt in via addLine({ yAxis }).
Parameters
| Parameter | Type |
|---|---|
id | string |
opts | YAxisOptions |
Returns
void
autoscale()
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()
clearAnnotations(): void;Defined in: plot.ts:1102
Remove all annotations.
Returns
void
clearDrawings()
clearDrawings(): void;Defined in: plot.ts:1143
Remove every user drawing.
Returns
void
copyToClipboard()
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
| Parameter | Type |
|---|---|
opts | ExportOptions |
Returns
Promise<void>
dataAt()
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
| Parameter | Type |
|---|---|
clientX | number |
clientY | number |
Returns
| { x: number; y: number; } | null
describe()
describe(): string;Defined in: plot.ts:850
A one-line text summary of the chart (title + series), for a11y / tooltips.
Returns
string
destroy()
destroy(): void;Defined in: plot.ts:1641
Returns
void
downloadImage()
downloadImage(
filename?,
type?,
opts?): Promise<void>;Defined in: plot.ts:1601
Download the current view as an image (PNG by default).
Parameters
| Parameter | Type | Default value |
|---|---|---|
filename | string | "chart.png" |
type | string | "image/png" |
opts | ExportOptions | {} |
Returns
Promise<void>
getDrawings()
getDrawings(): Annotation[];Defined in: plot.ts:1138
All user drawings (trendlines, fib levels, …).
Returns
getDrawTool()
getDrawTool(): DrawTool | null;Defined in: plot.ts:1121
The active drawing tool, or null.
Returns
DrawTool | null
getMode()
getMode(): InteractionMode;Defined in: plot.ts:1533
Returns
hasYAxis()
hasYAxis(id): boolean;Defined in: plot.ts:1403
Whether a y axis with this id exists (the primary is always "y").
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
boolean
home()
home(): void;Defined in: plot.ts:1542
Reset to the home view: explicit domains restored, auto axes re-fit to data.
Returns
void
isEqualAspect()
isEqualAspect(): boolean;Defined in: plot.ts:1466
Whether setEqualAspect is currently on.
Returns
boolean
isLayerVisible()
isLayerVisible(layer): boolean;Defined in: plot.ts:1895
Whether a layer is currently drawn (hidden layers also drop out of autoscale).
Parameters
| Parameter | Type |
|---|---|
layer | Layer |
Returns
boolean
isOnScreen()
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()
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
| Parameter | Type |
|---|---|
cb | (dataX) => void |
Returns
() => void
onDrawToolChange()
onDrawToolChange(cb): () => void;Defined in: plot.ts:1126
Subscribe to draw-tool changes (used by the toolbar). Returns an unsubscribe fn.
Parameters
| Parameter | Type |
|---|---|
cb | (t) => void |
Returns
() => void
onModeChange()
onModeChange(cb): void;Defined in: plot.ts:1537
Parameters
| Parameter | Type |
|---|---|
cb | (mode) => void |
Returns
void
onViewChange()
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
| Parameter | Type |
|---|---|
cb | (x) => void |
Returns
() => void
onVisibilityChange()
onVisibilityChange(cb): () => void;Defined in: plot.ts:1917
Subscribe to show/hide changes (legend clicks included). Returns an unsubscribe fn.
Parameters
| Parameter | Type |
|---|---|
cb | (layer, visible) => void |
Returns
() => void
onYViewChange()
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
| Parameter | Type |
|---|---|
cb | (y) => void |
Returns
() => void
removeLayer()
removeLayer(layer): void;Defined in: plot.ts:1414
Parameters
| Parameter | Type |
|---|---|
layer | Layer |
Returns
void
removeYAxis()
removeYAxis(id): void;Defined in: plot.ts:1408
Remove a secondary y axis. No-op for the primary "y" or an unknown id.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
void
render()
render(): void;Defined in: plot.ts:1753
Returns
void
requestRender()
requestRender(): void;Defined in: plot.ts:1715
Returns
void
setAriaLabel()
setAriaLabel(text): void;Defined in: plot.ts:844
Set the chart's accessible label (aria-label). Pass undefined to auto-summarize.
Parameters
| Parameter | Type |
|---|---|
text | string | undefined |
Returns
void
setAxis()
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
| Parameter | Type |
|---|---|
dim | string |
config | Partial<AxisConfig> |
Returns
void
setDrawTool()
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
| Parameter | Type |
|---|---|
tool | DrawTool | null |
Returns
void
setEqualAspect()
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
| Parameter | Type |
|---|---|
on | boolean |
Returns
void
setLayerVisible()
setLayerVisible(layer, visible): void;Defined in: plot.ts:1900
Show or hide a layer, re-fitting the auto axes to what remains visible.
Parameters
| Parameter | Type |
|---|---|
layer | Layer |
visible | boolean |
Returns
void
setLinkedCursor()
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
| Parameter | Type |
|---|---|
dataX | number | null |
Returns
void
setMode()
setMode(mode): void;Defined in: plot.ts:1526
Parameters
| Parameter | Type |
|---|---|
mode | InteractionMode |
Returns
void
setView()
setView(view): void;Defined in: plot.ts:1471
Set (or lock) the visible domain. y targets the primary axis; use yAxes for others.
Parameters
| Parameter | Type |
|---|---|
view | { x?: Range; y?: Range; yAxes?: Record<string, Range>; } |
view.x? | Range |
view.y? | Range |
view.yAxes? | Record<string, Range> |
Returns
void
toBlob()
toBlob(type?, opts?): Promise<Blob | null>;Defined in: plot.ts:1596
Export the current view as a Blob (default PNG).
Parameters
| Parameter | Type | Default value |
|---|---|---|
type | string | "image/png" |
opts | ExportOptions | {} |
Returns
Promise<Blob | null>
toDataURL()
toDataURL(type?, opts?): string;Defined in: plot.ts:1591
Export the current view as a data URL (default PNG).
Parameters
| Parameter | Type | Default value |
|---|---|---|
type | string | "image/png" |
opts | ExportOptions | {} |
Returns
string
toggleLayer()
toggleLayer(layer): boolean;Defined in: plot.ts:1910
Flip a layer's visibility. Returns the new state.
Parameters
| Parameter | Type |
|---|---|
layer | Layer |
Returns
boolean