Skip to main content
Version: 4.1

lightweight-charts

Enumerations

Interfaces

Variables

customSeriesDefaultOptions

Const customSeriesDefaultOptions: CustomSeriesOptions

Functions

createChart

createChart(container, options?): IChartApi

This function is the simplified main entry point of the Lightweight Charting Library with time points for the horizontal scale.

Parameters

NameTypeDescription
containerstring | HTMLElementID of HTML element or element itself
options?DeepPartial<TimeChartOptions>Any subset of options to be applied at start.

Returns

IChartApi

An interface to the created chart


createChartEx

createChartEx<HorzScaleItem, THorzScaleBehavior>(container, horzScaleBehavior, options?): IChartApiBase<HorzScaleItem>

This function is the main entry point of the Lightweight Charting Library. If you are using time values for the horizontal scale then it is recommended that you rather use the createChart function.

Type parameters

NameTypeDescription
HorzScaleItemHorzScaleItemtype of points on the horizontal scale
THorzScaleBehaviorextends IHorzScaleBehavior<HorzScaleItem, THorzScaleBehavior>type of horizontal axis strategy that encapsulate all the specific behaviors of the horizontal scale type

Parameters

NameTypeDescription
containerstring | HTMLElementID of HTML element or element itself
horzScaleBehaviorTHorzScaleBehaviorHorizontal scale behavior
options?DeepPartial<ReturnType<THorzScaleBehavior["options"]>>Any subset of options to be applied at start.

Returns

IChartApiBase<HorzScaleItem>

An interface to the created chart


defaultHorzScaleBehavior

defaultHorzScaleBehavior(): () => IHorzScaleBehavior<Time>

Provides the default implementation of the horizontal scale (time-based) that can be used as a base for extending the horizontal scale with custom behavior. This allows for the introduction of custom functionality without re-implementing the entire IHorzScaleBehavior<Time> interface.

For further details, refer to the createChartEx chart constructor method.

Returns

fn

An uninitialized class implementing the IHorzScaleBehavior<Time> interface

• ()


isBusinessDay

isBusinessDay(time): time is BusinessDay

Check if a time value is a business day object.

Parameters

NameTypeDescription
timeTimeThe time to check.

Returns

time is BusinessDay

true if time is a BusinessDay object, false otherwise.


isUTCTimestamp

isUTCTimestamp(time): time is UTCTimestamp

Check if a time value is a UTC timestamp number.

Parameters

NameTypeDescription
timeTimeThe time to check.

Returns

time is UTCTimestamp

true if time is a UTCTimestamp number, false otherwise.


version

version(): string

Returns the current version as a string. For example '3.3.0'.

Returns

string

Type Aliases

AreaSeriesOptions

Ƭ AreaSeriesOptions: SeriesOptions<AreaStyleOptions>

Represents area series options.


AreaSeriesPartialOptions

Ƭ AreaSeriesPartialOptions: SeriesPartialOptions<AreaStyleOptions>

Represents area series options where all properties are optional.


AutoscaleInfoProvider

Ƭ AutoscaleInfoProvider: (baseImplementation: () => AutoscaleInfo | null) => AutoscaleInfo | null

Type declaration

▸ (baseImplementation): AutoscaleInfo | null

A custom function used to get autoscale information.

Parameters
NameTypeDescription
baseImplementation() => AutoscaleInfo | nullThe default implementation of autoscale algorithm, you can use it to adjust the result.
Returns

AutoscaleInfo | null


Background

Ƭ Background: SolidColor | VerticalGradientColor

Represents the background color of the chart.


BarPrice

Ƭ BarPrice: Nominal<number, "BarPrice">

Represents a price as a number.


BarSeriesOptions

Ƭ BarSeriesOptions: SeriesOptions<BarStyleOptions>

Represents bar series options.


BarSeriesPartialOptions

Ƭ BarSeriesPartialOptions: SeriesPartialOptions<BarStyleOptions>

Represents bar series options where all properties are options.


BaseValueType

Ƭ BaseValueType: BaseValuePrice

Represents a type of a base value of baseline series type.


BaselineSeriesOptions

Ƭ BaselineSeriesOptions: SeriesOptions<BaselineStyleOptions>

Structure describing baseline series options.


BaselineSeriesPartialOptions

Ƭ BaselineSeriesPartialOptions: SeriesPartialOptions<BaselineStyleOptions>

Represents baseline series options where all properties are options.


CandlestickSeriesOptions

Ƭ CandlestickSeriesOptions: SeriesOptions<CandlestickStyleOptions>

Represents candlestick series options.


CandlestickSeriesPartialOptions

Ƭ CandlestickSeriesPartialOptions: SeriesPartialOptions<CandlestickStyleOptions>

Represents candlestick series options where all properties are optional.


ChartOptions

Ƭ ChartOptions: TimeChartOptions

Structure describing options of the chart with time points at the horizontal scale. Series options are to be set separately


Coordinate

Ƭ Coordinate: Nominal<number, "Coordinate">

Represents a coordiate as a number.


CreatePriceLineOptions

Ƭ CreatePriceLineOptions: Partial<PriceLineOptions> & Pick<PriceLineOptions, "price">

Price line options for the createPriceLine method.

price is required, while the rest of the options are optional.


CustomSeriesOptions

Ƭ CustomSeriesOptions: SeriesOptions<CustomStyleOptions>

Represents a custom series options.


CustomSeriesPartialOptions

Ƭ CustomSeriesPartialOptions: SeriesPartialOptions<CustomStyleOptions>

Represents a custom series options where all properties are optional.


CustomSeriesPricePlotValues

Ƭ CustomSeriesPricePlotValues: number[]

Price values for the custom series. This list should include the largest, smallest, and current price values for the data point. The last value in the array will be used for the current value. You shouldn't need to have more than 3 values in this array since the library only needs a largest, smallest, and current value.

Examples:

  • For a line series, this would contain a single number representing the current value.
  • For a candle series, this would contain the high, low, and close values. Where the last value would be the close value.

DataChangedHandler

Ƭ DataChangedHandler: (scope: DataChangedScope) => void

Type declaration

▸ (scope): void

A custom function use to handle data changed events.

Parameters
NameType
scopeDataChangedScope
Returns

void


DataChangedScope

Ƭ DataChangedScope: "full" | "update"

The extent of the data change.


DataItem

Ƭ DataItem<HorzScaleItem>: SeriesDataItemTypeMap<HorzScaleItem>[SeriesType]

Represents the type of data that a series contains.

Type parameters

Name
HorzScaleItem

DeepPartial

Ƭ DeepPartial<T>: { [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends readonly (infer X)[] ? readonly DeepPartial<X>[] : DeepPartial<T[P]> }

Represents a type T where every property is optional.

Type parameters

Name
T

HistogramSeriesOptions

Ƭ HistogramSeriesOptions: SeriesOptions<HistogramStyleOptions>

Represents histogram series options.


HistogramSeriesPartialOptions

Ƭ HistogramSeriesPartialOptions: SeriesPartialOptions<HistogramStyleOptions>

Represents histogram series options where all properties are optional.


HorzAlign

Ƭ HorzAlign: "left" | "center" | "right"

Represents a horizontal alignment.


HorzScaleItemConverterToInternalObj

Ƭ HorzScaleItemConverterToInternalObj<HorzScaleItem>: (time: HorzScaleItem) => InternalHorzScaleItem

Type parameters

Name
HorzScaleItem

Type declaration

▸ (time): InternalHorzScaleItem

Function for converting a horizontal scale item to an internal item.

Parameters
NameType
timeHorzScaleItem
Returns

InternalHorzScaleItem


ISeriesPrimitive

Ƭ ISeriesPrimitive<HorzScaleItem>: ISeriesPrimitiveBase<SeriesAttachedParameter<HorzScaleItem, SeriesType>>

Interface for series primitives. It must be implemented to add some external graphics to series.

Type parameters

NameType
HorzScaleItemTime

InternalHorzScaleItem

Ƭ InternalHorzScaleItem: Nominal<unknown, "InternalHorzScaleItem">

Internal Horizontal Scale Item


InternalHorzScaleItemKey

Ƭ InternalHorzScaleItemKey: Nominal<number, "InternalHorzScaleItemKey">

Index key for a horizontal scale item.


LineSeriesOptions

Ƭ LineSeriesOptions: SeriesOptions<LineStyleOptions>

Represents line series options.


LineSeriesPartialOptions

Ƭ LineSeriesPartialOptions: SeriesPartialOptions<LineStyleOptions>

Represents line series options where all properties are optional.


LineWidth

Ƭ LineWidth: 1 | 2 | 3 | 4

Represents the width of a line.


Logical

Ƭ Logical: Nominal<number, "Logical">

Represents the to or from number in a logical range.


LogicalRange

Ƭ LogicalRange: Range<Logical>

A logical range is an object with 2 properties: from and to, which are numbers and represent logical indexes on the time scale.

The starting point of the time scale's logical range is the first data item among all series. Before that point all indexes are negative, starting from that point - positive.

Indexes might have fractional parts, for instance 4.2, due to the time-scale being continuous rather than discrete.

Integer part of the logical index means index of the fully visible bar. Thus, if we have 5.2 as the last visible logical index (to field), that means that the last visible bar has index 5, but we also have partially visible (for 20%) 6th bar. Half (e.g. 1.5, 3.5, 10.5) means exactly a middle of the bar.


LogicalRangeChangeEventHandler

Ƭ LogicalRangeChangeEventHandler: (logicalRange: LogicalRange | null) => void

Type declaration

▸ (logicalRange): void

A custom function used to handle changes to the time scale's logical range.

Parameters
NameType
logicalRangeLogicalRange | null
Returns

void


MouseEventHandler

Ƭ MouseEventHandler<HorzScaleItem>: (param: MouseEventParams<HorzScaleItem>) => void

Type parameters

Name
HorzScaleItem

Type declaration

▸ (param): void

A custom function use to handle mouse events.

Parameters
NameType
paramMouseEventParams<HorzScaleItem>
Returns

void


Mutable

Ƭ Mutable<T>: { -readonly [P in keyof T]: T[P] }

Removes "readonly" from all properties

Type parameters

Name
T

Nominal

Ƭ Nominal<T, Name>: T & { [species]: Name }

This is the generic type useful for declaring a nominal type, which does not structurally matches with the base type and the other types declared over the same base type

Example

type Index = Nominal<number, 'Index'>;
// let i: Index = 42; // this fails to compile
let i: Index = 42 as Index; // OK

Example

type TagName = Nominal<string, 'TagName'>;

Type parameters

NameType
TT
Nameextends string

OverlayPriceScaleOptions

Ƭ OverlayPriceScaleOptions: Omit<PriceScaleOptions, "visible" | "autoScale">

Represents overlay price scale options.


PercentageFormatterFn

Ƭ PercentageFormatterFn: (percentageValue: number) => string

Type declaration

▸ (percentageValue): string

A function used to format a percentage value as a string.

Parameters
NameType
percentageValuenumber
Returns

string


PriceFormat

Ƭ PriceFormat: PriceFormatBuiltIn | PriceFormatCustom

Represents information used to format prices.


PriceFormatterFn

Ƭ PriceFormatterFn: (priceValue: BarPrice) => string

Type declaration

▸ (priceValue): string

A function used to format a BarPrice as a string.

Parameters
NameType
priceValueBarPrice
Returns

string


PriceToCoordinateConverter

Ƭ PriceToCoordinateConverter: (price: number) => Coordinate | null

Type declaration

▸ (price): Coordinate | null

Converter function for changing prices into vertical coordinate values.

This is provided as a convenience function since the series original data will most likely be defined in price values, and the renderer needs to draw with coordinates. This returns the same values as directly using the series' priceToCoordinate method.

Parameters
NameType
pricenumber
Returns

Coordinate | null


SeriesMarkerPosition

Ƭ SeriesMarkerPosition: "aboveBar" | "belowBar" | "inBar"

Represents the position of a series marker relative to a bar.


SeriesMarkerShape

Ƭ SeriesMarkerShape: "circle" | "square" | "arrowUp" | "arrowDown"

Represents the shape of a series marker.


SeriesOptions

Ƭ SeriesOptions<T>: T & SeriesOptionsCommon

Represents the intersection of a series type T's options and common series options.

See

SeriesOptionsCommon for common options.

Type parameters

Name
T

SeriesPartialOptions

Ƭ SeriesPartialOptions<T>: DeepPartial<T & SeriesOptionsCommon>

Represents a SeriesOptions where every property is optional.

Type parameters

Name
T

SeriesPrimitivePaneViewZOrder

Ƭ SeriesPrimitivePaneViewZOrder: "bottom" | "normal" | "top"

Defines where in the visual layer stack the renderer should be executed.

  • bottom: Draw below everything except the background.
  • normal: Draw at the same level as the series.
  • top: Draw above everything (including the crosshair).

SeriesType

Ƭ SeriesType: keyof SeriesOptionsMap

Represents a type of series.

See

SeriesOptionsMap


SizeChangeEventHandler

Ƭ SizeChangeEventHandler: (width: number, height: number) => void

Type declaration

▸ (width, height): void

A custom function used to handle changes to the time scale's size.

Parameters
NameType
widthnumber
heightnumber
Returns

void


TickMarkFormatter

Ƭ TickMarkFormatter: (time: Time, tickMarkType: TickMarkType, locale: string) => string | null

Type declaration

▸ (time, tickMarkType, locale): string | null

The TickMarkFormatter is used to customize tick mark labels on the time scale.

This function should return time as a string formatted according to tickMarkType type (year, month, etc) and locale.

Note that the returned string should be the shortest possible value and should have no more than 8 characters. Otherwise, the tick marks will overlap each other.

If the formatter function returns null then the default tick mark formatter will be used as a fallback.

Example

const customFormatter = (time, tickMarkType, locale) => {
// your code here
};
Parameters
NameType
timeTime
tickMarkTypeTickMarkType
localestring
Returns

string | null


TickMarkWeightValue

Ƭ TickMarkWeightValue: Nominal<number, "TickMarkWeightValue">

Weight of the tick mark.

See

TickMarkWeight enum


Time

Ƭ Time: UTCTimestamp | BusinessDay | string

The Time type is used to represent the time of data items.

Values can be a UTCTimestamp, a BusinessDay, or a business day string in ISO format.

Example

const timestamp = 1529899200; // Literal timestamp representing 2018-06-25T04:00:00.000Z
const businessDay = { year: 2019, month: 6, day: 1 }; // June 1, 2019
const businessDayString = '2021-02-03'; // Business day string literal

TimeFormatterFn

Ƭ TimeFormatterFn<HorzScaleItem>: (time: HorzScaleItem) => string

Type parameters

NameType
HorzScaleItemTime

Type declaration

▸ (time): string

A custom function used to override formatting of a time to a string.

Parameters
NameType
timeHorzScaleItem
Returns

string


TimePointIndex

Ƭ TimePointIndex: Nominal<number, "TimePointIndex">

Index for a point on the horizontal (time) scale.


TimeRangeChangeEventHandler

Ƭ TimeRangeChangeEventHandler<HorzScaleItem>: (timeRange: Range<HorzScaleItem> | null) => void

Type parameters

Name
HorzScaleItem

Type declaration

▸ (timeRange): void

A custom function used to handle changes to the time scale's time range.

Parameters
NameType
timeRangeRange<HorzScaleItem> | null
Returns

void


UTCTimestamp

Ƭ UTCTimestamp: Nominal<number, "UTCTimestamp">

Represents a time as a UNIX timestamp.

If your chart displays an intraday interval you should use a UNIX Timestamp.

Note that JavaScript Date APIs like Date.now return a number of milliseconds but UTCTimestamp expects a number of seconds.

Note that to prevent errors, you should cast the numeric type of the time to UTCTimestamp type from the package (value as UTCTimestamp) in TypeScript code.

Example

const timestamp = 1529899200 as UTCTimestamp; // Literal timestamp representing 2018-06-25T04:00:00.000Z
const timestamp2 = (Date.now() / 1000) as UTCTimestamp;

VertAlign

Ƭ VertAlign: "top" | "center" | "bottom"

Represents a vertical alignment.


VisiblePriceScaleOptions

Ƭ VisiblePriceScaleOptions: PriceScaleOptions

Represents a visible price scale's options.

See

PriceScaleOptions