Skip to main content

Interface: IPriceScaleApi

Charting Library.IPriceScaleApi

The Price Scale API allows interacting with the price scale. You can retrieve this interface by evoking the following methods of the IPaneApi:

  • getLeftPriceScales
  • getRightPriceScales
  • getMainSourcePriceScale

Methods​

coordinateToPrice​

coordinateToPrice(coordinate): number

Converts a vertical coordinate to the price it points at.

The coordinate is measured in pixels from the top of the pane the price scale belongs to. The conversion follows the current state of the price scale, so the same coordinate maps to different prices after the scale is zoomed, inverted, or switched to another PriceScaleMode.

Returns null when the price scale has no data to convert against — for example before the first bars arrive.

Note that the value is only correct for the frame in which it was requested. The chart is not redrawn when you call this method, and any overlay you position from the result is not part of the chart's own rendering, so it will lag behind while the user scrolls or scales the chart.

Parameters​

NameTypeDescription
coordinatenumbervertical coordinate in pixels, measured from the top of the pane

Returns​

number


currency​

currency(): CurrencyInfo

Returns the current currency set on the price scale. Returns null if no currency is specified.

Returns​

CurrencyInfo


getMode​

getMode(): PriceScaleMode

Returns current mode of the price scale

Returns​

PriceScaleMode


getStudies​

getStudies(): EntityId[]

Returns an array of IDs of all studies attached to the price scale

Returns​

EntityId[]


getVisiblePriceRange​

getVisiblePriceRange(): VisiblePriceRange

Returns current visible price range of the price scale. The result is an object with from and to, which are the boundaries of the price scale visible range.

Returns​

VisiblePriceRange


hasMainSeries​

hasMainSeries(): boolean

Returns true if the price scale contains the main series

Returns​

boolean


isAutoScale​

isAutoScale(): boolean

Returns true when the price scale has auto scaling enabled

Returns​

boolean


isInverted​

isInverted(): boolean

Returns whether the price scale is inverted or not

Returns​

boolean


isLocked​

isLocked(): boolean

Returns true when the price scale is locked

Returns​

boolean


priceToCoordinate​

priceToCoordinate(price): number

Converts a price to the vertical coordinate at which it is displayed. This is the inverse of IPriceScaleApi.coordinateToPrice and carries the same caveats.

Parameters​

NameTypeDescription
pricenumberprice to convert

Returns​

number


setAutoScale​

setAutoScale(isAutoScale): void

Set whether auto scaling should be enabled or not for the price scale

Parameters​

NameTypeDescription
isAutoScalebooleanset to true to enable auto scaling

setCurrency​

setCurrency(currency): void

Sets a currency on the price scale.

Parameters​

NameTypeDescription
currencystringcurrency supported by your backend (for example 'EUR', 'USD'). A null value will reset the currency to default.

setInverted​

setInverted(isInverted): void

Changes current inverted state of the price scale

Parameters​

NameTypeDescription
isInvertedbooleanset to true if the price scale should become inverted

setLocked​

setLocked(isLocked): void

Set whether the price scale should be locked or not

Parameters​

NameTypeDescription
isLockedbooleanset to true to lock the price scale

setMode​

setMode(newMode): void

Changes current mode of the price scale

Parameters​

NameTypeDescription
newModePriceScaleModenew mode to set for the price scale

setUnit​

setUnit(unit): void

Sets a unit on the price scale.

Parameters​

NameTypeDescription
unitstringunit supported by your backend (for example 'weight', 'energy'). A null value will reset the unit to default.

setVisiblePriceRange​

setVisiblePriceRange(range): void

Sets current visible price range of the price scale,

Parameters​

NameTypeDescription
rangeVisiblePriceRangean object with from and to, which are the boundaries of the price scale visible range.

unit​

unit(): UnitInfo

Returns the current unit set on the price scale. Returns null if no unit is specified.

Returns​

UnitInfo