Skip to main content
← Back to plugin catalog

Anchored text

NewOverlaysWorks with lightweight-charts ^5.0.0v1.0.0

Text label anchored to an edge, a corner or the center of a pane, on a series or a pane, with configurable margins.

Interactive example — the real plugin running on a live chart. Scroll, zoom, and hover. Open the full demo

A single line of text anchored to an edge, a corner or the center of a pane, as a series primitive (AnchoredText) or as a pane primitive (AnchoredTextPane). The text keeps its place while the chart scrolls and zooms, inset from the pane edges by a margin you choose. The text, its anchor, margins, font, color, layer and visibility can all be changed after the primitive has been attached.

The series primitive belongs to the series it is attached to: it lives in that series' pane and is removed together with the series. The pane primitive needs no series at all.

Use it for a chart title, a symbol or interval label, a data-source credit, or a "preview" or "draft" stamp.

Lightweight Charts™ 5 also ships a built-in text watermark. createTextWatermark(pane, options) is a pane primitive which draws one or more lines of text, centered by default and scaled down to fit the pane. If that is all you need, the built-in function is the right choice. Use this package for text tied to a specific series rather than to a pane, or for what the built-in does not offer: margins from the pane edge, a CSS font shorthand, zOrder and setText.

Installation​

Install the package. It requires lightweight-charts ^5.0.0 in your project:

npm install @tradingview/lwc-plugin-anchored-text

Then import the plugin and add it to a chart:

import { createChart, LineSeries } from 'lightweight-charts';
import { AnchoredText } from '@tradingview/lwc-plugin-anchored-text';

const chart = createChart(document.getElementById('container'));
const series = chart.addSeries(LineSeries);
series.setData(data);

series.attachPrimitive(new AnchoredText({ text: 'BTC/USD · 1D' }));

Usage​

On a series​

Create the text, then attach it to the series whose pane it should sit in:

import { createChart, LineSeries } from 'lightweight-charts';
import { AnchoredText } from '@tradingview/lwc-plugin-anchored-text';

const chart = createChart(document.getElementById('container'));
const series = chart.addSeries(LineSeries);
series.setData(data);

const title = new AnchoredText({
text: 'BTC/USD · 1D',
horzAlign: 'right',
vertAlign: 'top',
font: 'bold 16px sans-serif',
color: '#2962FF',
});
series.attachPrimitive(title);

To remove the text, detach it from the series:

series.detachPrimitive(title);

On a pane​

AnchoredTextPane takes the same options and is attached to a pane instead of a series. Use it when the text should stay put while series are added and removed:

import { AnchoredTextPane } from '@tradingview/lwc-plugin-anchored-text';

const title = new AnchoredTextPane({ text: 'Volume', vertAlign: 'bottom' });
chart.panes()[1].attachPrimitive(title);

// later
chart.panes()[1].detachPrimitive(title);

Changing the text​

Both classes have the same methods:

title.applyOptions({ horzAlign: 'center', color: '#787B86' });
title.setText('ETH/USD · 1D'); // same as applyOptions({ text })
title.options(); // the current options, with the defaults filled in

applyOptions merges: an option which is not passed, or is passed as undefined, is left unchanged. The one exception is lineHeight: passing lineHeight: undefined goes back to measuring the height from the font.

Options​

Options are passed as the constructor argument, which is optional, as is every option in it. The type is AnchoredTextOptions, and the defaults are exported as defaultOptions.

OptionTypeDefaultDescription
textstring''The line of text. An empty string draws nothing.
horzAlign'left' | 'center' | 'right''left'Which side of the pane the text is anchored to, or centered.
vertAlign'top' | 'center' | 'bottom''top'Which edge of the pane the text is anchored to, or centered.
horzMarginnumber20Distance from the left or right pane edge, in CSS pixels. Not used when horzAlign is 'center'.
vertMarginnumber10Distance from the top or bottom pane edge, in CSS pixels. Not used when vertAlign is 'center'.
fontstringbold 14px system sans-serifFont, as a CSS font shorthand.
lineHeightnumber— (measured)Height of the text, in CSS pixels. Measured from the font when not set.
colorstring'#131722'Text color.
visiblebooleantrueWhether the text is drawn at all.
zOrder'bottom' | 'normal' | 'top''normal'Layer the text is drawn in. 'normal' draws it with the series, under the crosshair; 'top' puts it over everything in the pane, the crosshair included; 'bottom' puts it behind the series.

Alignment and margins​

The text is placed against the anchored edge of its pane, horzMargin and vertMargin away from it. A centered axis ignores its margin. With a lineHeight the text's baseline sits at the bottom of that height, as it did in the plugin-examples version; without one the height is that of the font, so it does not change with the text, and the baseline sits at the font's ascent.

Notes​

  • The text is drawn on one line, as given. It is neither wrapped nor scaled: text wider than the pane is clipped at the pane edge. The built-in createTextWatermark scales its text down to fit, if that is what you need.
  • The text appears only in the pane it belongs to. It never covers the price scales or the time scale, and a visible left price scale or a second pane does not move it.
  • Sizes are in CSS pixels; the text is drawn in the media coordinate space, so it stays sharp at any device pixel ratio.
  • 'middle' is still accepted as a value of horzAlign and vertAlign, the spelling used in the plugin-examples collection, and is read as 'center'. It is kept for compatibility and will be removed in a future major version.

Metadata​

PublisherTradingView (official)
npm package@tradingview/lwc-plugin-anchored-text
Version1.0.0
Supported rangelightweight-charts ^5.0.0
Plugin typeseries-primitive
LicenseApache-2.0
PublishedNov 13, 2026
Tagstextlabeltitleannotationoverlaywatermark
Repositorytradingview/lightweight-charts/tree/master/packages/lwc-plugin-anchored-text