website/tutorials/how_to/price-line.mdx
A price line is a horizontal line drawn across the width of the chart at a specific price value. This example shows how to add price lines to your chart.
A price line can be added to a chart by using the
createPriceLine method on an existing series
(ISeriesApi) instance.
const myPriceLine = {
price: 1234,
color: '#3179F5',
lineWidth: 2,
lineStyle: 2, // LineStyle.Dashed
axisLabelVisible: true,
title: 'my label',
};
series.createPriceLine(myPriceLine);
You can see a full working example below.
You may wish to disable the default price line drawn by Lightweight Charts™ for the last value in the series (and it's label). You can do this by adjusting the series options as follows:
series.applyOptions({
lastValueVisible: false,
priceLineVisible: false,
});
You can view the related APIs here:
import UsageGuidePartial from "../_usage-guide-partial.mdx"; import CodeBlock from "@theme/CodeBlock"; import code from "!!raw-loader!./price-line.js";
<CodeBlock replaceThemeConstants chart className="language-js" hideableCode chartOnTop codeUsage={<UsageGuidePartial />}> {code} </CodeBlock>