Skip to content
EliteChart

OverlayFn

Documentation


Documentation / @elitechart/core / OverlayFn

code
type OverlayFn = (paint, viewport, bars) => void;

Defined in: chart.ts:209

Overlay render function — invoked on the Overlay layer each frame.

Overlays receive a backend-neutral Paint, the current Viewport, and the current bars. Use viewport.timeToX(...) / viewport.priceToY(...) to map indicator values to canvas pixels.

Overlays are the simplest form of the plugin seam formalized in M6. They are intended for user-level overlays (SMA, EMA, custom markers). Heavy compute should be cached or off-loaded — overlays are called on every repaint of the Overlay layer.

Parameters

paint

Paint

viewport

Viewport

bars

readonly Bar[]

Returns

void

Example

code
import type { OverlayFn } from '@elitechart/core';
const lastClose: OverlayFn = (paint, vp, bars) => {
  const last = bars[bars.length - 1];
  if (last === undefined) return;
  const y = vp.priceToY(last.close);
  paint.fillRect(vp.plotLeft, y - 1, vp.plotWidth, 2, '#4f8cff');
};
const off = chart.addOverlay(lastClose);
// later: off();