Text watermark
Styling
A text watermark drawn behind the series.
Interactive example — scroll, zoom, and hover the chart.
Code
// Lightweight Charts™ Example: Watermark Simple
// https://tradingview.github.io/lightweight-charts/examples/styling/text-watermark
const chartOptions = {
layout: {
textColor: 'black',
background: { type: 'solid', color: 'white' },
},
grid: {
vertLines: { color: '#D6DCDE' },
horzLines: { color: '#D6DCDE' },
},
};
/** @type {import('lightweight-charts').IChartApi} */
const chart = createChart(document.getElementById('container'), chartOptions);
/** @type {import('lightweight-charts').createTextWatermark} */
createTextWatermark(chart.panes()[0], {
horzAlign: 'center',
vertAlign: 'center',
lines: [
{
text: 'Watermark Example',
color: 'rgba(171, 71, 188, 0.5)',
fontSize: 24,
},
],
});
const lineSeries = chart.addSeries(AreaSeries, {
topColor: '#2962FF',
bottomColor: 'rgba(41, 98, 255, 0.28)',
lineColor: '#2962FF',
lineWidth: 2,
});
const data = [
{ value: 0, time: 1642425322 },
];
lineSeries.setData(data);
chart.timeScale().fitContent();
The code expects the library’s exports, such as createChart, to be imported and a div with the id container on the page. Copy as HTML gives a page that runs on its own.
How it works
A text watermark is one or more lines of text drawn behind the series in a pane.
createTextWatermark adds the watermark to the first pane, from panes. The options set its alignment and, for each line, the text, color, and font size. The call is highlighted in the code.
Tips
- The function returns the watermark. Call its
applyOptionsto change the text later. - For an image instead of text, see Image watermark.
Resources
createTextWatermarkTextWatermarkOptions- Related examples: Image watermark