Kumo Charts

@kumo-charts/core

API 参考由源码注释生成,只有英文。

import { … } from '@kumo-charts/core';

Functions

canBuildTimeframefunction源码

function canBuildTimeframe(timeframe: IntervalInput, source: IntervalInput): boolean

Whether bars of timeframe can be built from bars of the source interval: a multiple of it, or days, weeks and months from bars that divide a day. canBuildTimeframe('4h', '1h') is true.

checkColorfunction源码

function checkColor(path: string, value: unknown): string

Checks a color as the chart takes it: hex, rgb() or rgba(), or any other CSS color the browser's canvas paints. Without a canvas, as in Node, nothing is painted, and any text is taken.

checkTimeframefunction源码

function checkTimeframe(timeframe: IntervalInput, source: IntervalInput): void

Throws unless bars of timeframe can be built from bars of the source interval, saying why, as chart.setTimeframe() does: checkTimeframe('1W', '2D') throws, as weeks are built from 1D bars.

createCalendarfunction源码

function createCalendar(input: CalendarInput = {}): Calendar

Creates the calendar the chart uses to build timeframes, for aligning your own data. Options are those of the chart's calendar option; timeZone defaults to UTC, as there.

const calendar = createCalendar({ timeZone: 'Asia/Shanghai', sessions: ['09:30-11:30', '13:00-15:00'] });
calendar.bucket('2024-05-06T02:15:00Z', '1h'); // 09:30 Shanghai time, the bar 10:15 falls in

createChartfunction源码

function createChart<const M extends readonly ChartModule[] = readonly []>(
  container: HTMLElement,
  options?: CreateChartOptions<M>
): Chart<M>

Creates a chart inside container with the given modules. The chart fills the container and follows its size unless autoSize is off.

const chart = createChart(document.getElementById('chart')!, {
  modules: [indicators(allIndicators)],
  locale: 'zh-CN'
});
chart.data.set(bars);
chart.indicators.add({ type: 'MACD' });

createModulefunction源码

function createModule<
  Types extends ModuleTypes = ModuleTypes,
  Api extends object = NonNullable<Types['api']>
>(definition: ModuleDefinition<Types, Api>): ChartModule<Types & { readonly api: Api }>

A module of an application or another package, such as one registering its own indicator or drawing types: install runs on the chart once the chart and the library's modules given with it are there, before the chart uses its options, so the options can use the types it registers. What it returns joins the chart as namespaces, e.g. { footprint: footprintApi } becomes chart.footprint. A module may add a section of options, emit events of its own and keep a part of the saved state; Types says what it adds, as ChartModule<Types> does. Without Types, the namespaces are those install returns.

interface StampTypes {
  api: { stamp: { count(): number } };
  options: { stamp: { text: string } };
  events: { stampChange: { text: string } };
}

const stamp = createModule<StampTypes>({
  name: 'stamp',
  options: { key: 'stamp', defaults: () => ({ text: '' }), validate: () => {} },
  install: (chart, context) => {
    chart.on('optionsChange', ({ options, previous }) => {
      if (options.stamp.text !== previous.stamp.text) {
        context.emit('stampChange', { text: context.options().text });
      }
    });
    return { stamp: { count: () => context.options().text.length } };
  }
});

formatIntervalfunction源码

function formatInterval(interval: IntervalInput): string

The canonical shorthand of an interval: 15s, 5m, 4h, 1D, 1W, 3M.

intervalDurationfunction源码

function intervalDuration(interval: IntervalInput): number | null

The length in milliseconds of an interval of seconds, minutes or hours, such as '15m'; null for days, weeks and months, whose lengths the trading calendar gives.

parseBarfunction源码

function parseBar(input: BarInput, label = 'bar', index?: number): Bar

Checks a bar as the chart does and returns it normalized: the time in epoch milliseconds and the volume 0 when absent. Errors name the bar label, or label[index] with an index, such as bars[3].high must be a finite number, received null.

parseIntervalfunction源码

function parseInterval(input: IntervalInput, label = 'interval'): Interval

Parses an interval such as '5m', '4h', '1D' or { unit: 'week', count: 1 }. Throws a ChartError for anything else.

withAlphafunction源码

function withAlpha(color: string, alpha: number): string

Returns color with its alpha multiplied by alpha.

Classes

ChartErrorclass源码

class ChartError extends Error

Error thrown for every invalid argument, unknown id or illegal state reported by the library.

override readonly name = 'ChartError'
constructor(message: string)

Interfaces

AreaStyleinterface源码

interface AreaStyle
lineColor: string
lineWidth: number
topColor: string
bottomColor: string

Barinterface源码

interface Bar

A normalized candlestick. time is epoch milliseconds.

readonly time: number
readonly open: number
readonly high: number
readonly low: number
readonly close: number
readonly volume: number

BarColorContextinterface源码

interface BarColorContext

What mainSeries.barColor receives for one bar.

readonly index: number

Index of the displayed bar.

readonly bar: Bar
readonly indicator: (id: string, key?: string) => number

Output key (default: the first) of an indicator drawn on this bar; NaN where it has none.

BarInputinterface源码

interface BarInput

A candlestick as accepted by the data APIs.

open: number
high: number
low: number
close: number
volume?: number

Defaults to 0.

BarsChangeEventinterface源码

interface BarsChangeEvent

The displayed bars changed: data was set, streamed or prepended, the timeframe or transform changed, or a replay revealed or hid bars.

readonly change: BarChange

tail: only bars from from on changed or were appended; reset: any bar may have.

BarsViewinterface源码

interface BarsView

Read-only, columnar access to bars, for plugins and custom drawings. Accessors take an index from 0 to length - 1.

readonly length: number
readonly revision: number

Changes whenever the bars change; key caches by it.

time(index: number): number
open(index: number): number
high(index: number): number
low(index: number): number
close(index: number): number
volume(index: number): number
bar(index: number): Bar | null

The bar at index, or null outside the bars.

lowerBound(time: number): number

First index whose time is at or after time, or length when every bar is earlier.

BarTransformDefinitioninterface源码

interface BarTransformDefinition<P extends object = Record<string, unknown>>

Builds the displayed bars from the bars of the timeframe, such as Heikin-Ashi candles or Renko bricks. Register custom transforms with chart.transforms.register().

readonly type: string

The type the transform is set by, such as renko.

readonly name: string

Display name, such as Renko.

readonly keepsTime: boolean

Whether every input bar becomes one output bar with the same time, like Heikin-Ashi. The chart then keeps the features that rely on the timeframe, such as the bar countdown.

create(params: P, input: BarsView, from: 'bars' | 'trades'): BarTransformStream

Validates the parameters and starts a stream. input holds the bars the stream is about to receive, for statistics such as an automatic box size; from says what they are, the bars of the timeframe or the trades. The chart calls it again whenever the input is rebuilt (new data, timeframe, history or replay start); appended and updated bars resume the running stream.

BarTransformInputinterface源码

interface BarTransformInput
type: string
params?: Record<string, unknown>
input?: 'bars' | 'trades'

What the transform reads: bars, the bars of the timeframe (default), or trades, every trade passed to data.addTrades() that the chart keeps (performance.maxTrades), each as a bar whose open, high, low and close are its price and whose volume is its size.

BarTransformStateinterface源码

interface BarTransformState extends Required<BarTransformInput>

The transform building the displayed bars, as chart.transforms.get() reports it.

resolved: Readonly<Record<string, unknown>> | null

The parameters the bars are built with, as the transform reports them: defaults and sizes worked out from the bars filled in, such as { reversal: 2500 } for Kagi lines whose reversal follows the average true range. null for transforms that do not report them, and while the bars do not tell them yet.

BarTransformStreaminterface源码

interface BarTransformStream

A running transform: receives the input bars in order and builds the output bars.

next(bar: Bar, side: TradeSide | null): readonly Bar[]

Takes the next input bar; returns the output bars it completed, oldest first. A transform built from the trades gets the side of each trade's taker, null when unknown; one built from bars gets null.

current(): Bar | null

The output bar still forming after the latest input bar, or null.

An independent copy, which the chart uses to resume from before the latest input bar.

resolved?(): Readonly<Record<string, unknown>> | null

The parameters the stream builds with, defaults and sizes worked out from the bars filled in, such as { box: 2500, reversal: 3 } for an automatic box; null while the bars do not tell them yet. Optional: transforms.get() reports them as resolved, and a series type drawing the transform's bars reads them, as point & figure reads its box size.

BaselineStyleinterface源码

interface BaselineStyle
baseValue: number | null

Values above it use the top colors. null uses the first visible value.

lineWidth: number
topLineColor: string
topFillColor: string
bottomLineColor: string
bottomFillColor: string

ButtonClickEventinterface源码

interface ButtonClickEvent

A button in the label of an object, such as an order or an alert, was clicked.

readonly kind: ObjectKind
readonly id: string
readonly buttonId: string

Calendarinterface源码

interface Calendar

Buckets times into bars of any interval, following a trading calendar.

bucket(time: TimeInput, interval: IntervalInput): number | null

Start of the bar of interval that time belongs to, or null when the calendar drops it.

range(time: TimeInput, interval: IntervalInput): CalendarRange | null

The bar of interval that time belongs to and the run of times around time that belong to it too, or null when the calendar drops the time. Every time from start up to end has the same bucket, so a caller going through times in order asks again only from end on. A bar can take several runs, such as a day bar its morning and afternoon sessions. The run is the millisecond of time alone with the bucket option, whose results cannot be foreseen, and where a daylight-saving change comes close to a bar boundary.

CalendarOptionsinterface源码

interface CalendarOptions

The trading calendar that aggregates source bars and trades into timeframes.

timeZone: string

Zone the trading calendar is defined in, as the data times its bars: UTC (the default), as crypto exchanges do, or the zone of an exchange, such as America/New_York. The chart's timeZone only shows the times.

sessions: readonly string[]

Trading sessions of a trading day as 'HH:MM-HH:MM'; an end before its start crosses midnight. Times outside every session are dropped. Empty: trading around the clock.

dayStart: string

Wall-clock time a trading day starts. From this time on, times belong to the next date, e.g. '21:00' for night sessions or '17:00' for FX.

weekdays: readonly number[]

Weekdays that are trading days (0 = Sunday). A trading date on another weekday moves to the next trading weekday, so a Friday night session belongs to Monday.

weekStart: number

First day of a week bar (0 = Sunday).

bucket: CalendarBucket | null

CalendarRangeinterface源码

interface CalendarRange

A run of times that the calendar puts into one bar, from Calendar.range.

readonly bucket: number

Start of the bar, as bucket() returns it.

readonly start: number

The first time of the run.

readonly end: number

The end of the run, excluded.

CandleStyleinterface源码

interface CandleStyle
upColor: string
downColor: string
upWickColor: string
downWickColor: string
upBorderColor: string
downBorderColor: string
wick: boolean
border: boolean
bodyRatio: number

Body width as a fraction of the bar spacing.

hollowUp: boolean

Candles that close above their open are drawn hollow, their bodies outlined in upBorderColor whether border is on or not, as many traders read them. Candles and volume candles. Default false.

hollowDown: boolean

Candles that close below their open are drawn hollow, outlined in downBorderColor. Default false.

ChartBaseinterface源码

interface ChartBase<Options = unknown, Events = unknown, State = unknown>

The chart without the namespaces of its modules, which Chart adds.

readonly element: HTMLElement

The element the chart created inside its container.

options(): Readonly<ChartOptions & Options>

The resolved options.

applyOptions(options: DeepPartial<ChartOptions & Options>): void

Deep-merges option changes; arrays and functions are replaced.

layout(): Layout

Rectangles of the panes, the price axis and the time axis, for positioning custom overlays.

legendBounds(paneId?: string): Rect | null

Where the legend of a pane (the main one by default) was last painted, in CSS pixels as layout() gives them, such as for a button under it; null while it shows no row there.

resize(width: number, height: number): void

Sets the size in CSS pixels; with autoSize the container size wins on its next change.

batch(operation: () => void): void

Runs several API calls and dispatches their events once afterwards.

on<K extends keyof (ChartEventMap & Events)>(
  type: K,
  listener: (event: (ChartEventMap & Events)[K]) => void
): Unsubscribe
readonly data: DataApi
readonly transforms: TransformsApi
readonly timeScale: TimeScaleApi
priceScale(paneId?: string, scaleId?: string): PriceScaleApi

A price scale of a pane (default: the main pane): right (default), left, or an overlay scale named by the series and indicators placed on it.

readonly panes: PanesApi
readonly series: SeriesApi
readonly crosshair: CrosshairApi
readonly plugins: PluginsApi
modules(): string[]

The names of the chart's modules, in the order they were given.

select(selection: Selection | null): void

Selects a drawing, order, alert or marker, or clears the selection with null.

selection(): Selection | null

The selected object, or null.

saveState(): ChartState & State

The user-editable layout: main series type, view, panes, and what the modules keep.

loadState(state: ChartState): void

Restores a saved layout atomically; an invalid state throws and changes nothing.

screenshot(): HTMLCanvasElement

Renders pending changes and returns a canvas with the whole chart; an empty one when the chart has no size, as in a container that is hidden.

destroy(): void

Removes the chart's element and releases every listener, observer and timer. Every other call on the chart throws afterwards, a read as well as a change; calling it again does nothing.

ChartEventMapinterface源码

interface ChartEventMap
crosshairMove: CrosshairMoveEvent
visibleRangeChange: VisibleRangeChangeEvent
loadMore: LoadMoreEvent
doubleClick: ChartPointerEvent
contextMenu: ChartPointerEvent

Listening suppresses the browser's context menu over the chart.

selectionChange: SelectionChangeEvent
paneResize: PaneResizeEvent
buttonClick: ButtonClickEvent
legendButtonClick: LegendButtonClickEvent
barsChange: BarsChangeEvent
typesChange: TypesChangeEvent

Reports every registration, by the API too: no one feeds it back.

optionsChange: OptionsChangeEvent

ChartModuleinterface源码

interface ChartModule<Types extends ModuleTypes = ModuleTypes>

A part of the chart beyond its core, such as indicators or drawings, given to createChart(container, { modules }). Each module adds its namespace to the chart, e.g. chart.indicators, and may add options and events.

readonly name: string

Unique among the modules of a chart, such as indicators.

readonly '~types'?: Types

What the module adds, for the chart's types only: never set.

ChartOptionsinterface源码

interface ChartOptions
autoSize: boolean

Follows the container size with a ResizeObserver. When false, call chart.resize().

locale: string | null

BCP 47 locale for numbers and dates; null (default) uses the runtime's.

timeZone: string | null

IANA time zone such as Asia/Shanghai; null (default) uses the local time zone.

theme: Theme

The chart's colors: lightTheme by default, or darkTheme, or one of your own.

mainSeries: MainSeriesOptions
priceScale: PriceScaleOptions
latestPrice: LatestPriceOptions
interaction: InteractionOptions
performance: PerformanceOptions

Overrides of the words the chart paints, such as the legend's labels; null keeps a word.

ChartPlugininterface源码

interface ChartPlugin

Extends a chart from the outside: paints in the panes and uses the public API, e.g. to register drawing types or listen to events. Add it with chart.plugins.add().

readonly name: string

Unique among the chart's plugins.

attach?(host: PluginHost): void

Called when the plugin is added.

detach?(): void

Called when the plugin is removed or the chart is destroyed.

paint?(context: PluginPaintContext): void

Called for every pane, once per layer, whenever the chart repaints its series.

ChartPointerEventinterface源码

interface ChartPointerEvent

A click, double click or context menu on the chart.

readonly x: number

CSS pixel position inside the chart.

readonly y: number
readonly area: ChartArea
readonly paneId: string | null

The pane whose plot or price axis is under the pointer.

readonly scaleId: string | null

Over a price axis, its scale, such as right or left, for chart.priceScale().

readonly index: number | null

Logical bar index under the pointer, over a plot or the time axis.

readonly time: number | null
readonly price: number | null

The value at y in the pane's scale, or in the scale of the price axis under the pointer.

readonly target: ObjectTarget | null

ChartStateinterface源码

interface ChartState

The user-editable layout of a chart: main series type, view and panes, and what the modules keep of theirs under their keys, such as indicators and drawings. Market data, series, orders, markers and alerts belong to the application and are not included.

readonly version: 1
readonly mainSeries: { readonly type: SeriesType; readonly source: PriceSource }
readonly transform?: BarTransformInput | null

The transform building the displayed bars, such as Renko, or null for the bars of the timeframe. saveState() always writes it; a state without it leaves the transform as it is.

readonly view: { readonly barSpacing: number; readonly offset: number }
readonly panes: ReadonlyArray<{
  readonly id: string;
  readonly title: string;
  readonly height: number;
  readonly auto: boolean;
  readonly mode: PriceScaleMode;
  readonly inverted: boolean;
  /** Manual range in scale space, or `null` while auto-scaling. */
  readonly range: PriceRange | null;
  /** The right scale's margins, or `null` to follow `priceScale.margins`. */
  readonly margins?: ScaleMargins | null;
  /** The left and overlay scales. */
  readonly scales?: ReadonlyArray<SavedScale>;
}>
readonly [part: string]: unknown

What the modules keep, by their keys.

ChartTextsinterface源码

interface ChartTexts

Words the chart paints on the canvas, alike in every language unless they are set.

legendOpen: string

Labels of the main series' open, high, low, close and volume in the legend: O, H, …

legendHigh: string
legendLow: string
legendClose: string
legendVolume: string
days: (count: number) => string

Whole days of the countdown to the bar's close, 2d in 2d 03:15:00.

CollectionApiinterface源码

interface CollectionApi<Input, Item>

What the API offers of a collection of objects drawn on the objects layer.

set(inputs: readonly Input[]): void

Replaces every object, e.g. with the latest state from the broker. An invalid input throws and changes nothing.

add(input: Input): string

Adds an object and returns its id: the one it has, or one the chart numbers for it.

update(id: string, patch: Partial<Omit<Input, 'id'>>): void

Changes an object; what the patch leaves out stays. Throws for an unknown id.

remove(id: string): void

Throws for an unknown id.

clear(): void

Removes every object.

get(id: string): Item | null

The object of an id, or null.

list(): Item[]

Every object, in the order they were added.

ColumnsStyleinterface源码

interface ColumnsStyle
upColor: string
downColor: string
base: number | null

Columns grow from this value; null from the bottom of the pane, as price columns do, and so does a value the scale cannot show, such as 0 on a logarithmic one.

widthRatio: number

Column width as a fraction of the bar spacing.

CrosshairApiinterface源码

interface CrosshairApi
get(): CrosshairState | null

Where the crosshair is, or null while it is hidden.

set(position: { time: TimeInput; price?: number; pane?: string } | null): void

Shows the crosshair at a time (and optionally a value of a pane) without a pointer, for example to mirror another chart, or hides it with null. Pointer movement takes over again.

CrosshairLabelOptionsinterface源码

interface CrosshairLabelOptions

The crosshair's labels on the axes, of the time and the price at it.

visible: boolean
priceLines: CrosshairPriceLines | null

Lines of text under the price label on the right price axis, such as how far the price is from the latest: given the price at the pointer and the id of its pane, in the label's colors, the whole label centered on the pointer. None, or null, for the price alone.

avoidLatest: boolean

Keeps the price label on the right price axis clear of the labels there of the latest price and the latest values: where it would cover them it sits against them, above or below, on the side of the pointer, and stays there as the pointer moves over them. Otherwise it is at the pointer, over them.

CrosshairOptionsinterface源码

interface CrosshairOptions
mode: 'magnet' | 'free'

magnet snaps the horizontal line to the close of the hovered bar.

vertical: boolean
horizontal: boolean
style: LineStyle
snapToBars: boolean

Puts the vertical line on the middle of the bar under the pointer, so that it steps from bar to bar; off, it follows the pointer smoothly, its time label and the legend those of the bar under it all the same.

syncedOpacity: number

How opaque the crosshair is where the code sets it (crosshair.set()), such as the one another chart's pointer shows on a chart synced to it: its lines and its labels, from 0 to 1. Lighter than the pointer's own, it does not draw the eye from the chart the user is on.

CrosshairStateinterface源码

interface CrosshairState

Where the crosshair points.

readonly x: number

CSS pixel position inside the chart.

readonly y: number
readonly paneId: string | null

Pane under the pointer, or null over the time axis.

readonly index: number

Logical bar index under the pointer; may lie beyond the data.

readonly time: number | null
readonly price: number | null

Value at y in the pane's scale, or null outside the panes.

readonly bar: Bar | null

The hovered bar, or null outside the data.

DataApiinterface源码

interface DataApi

The main OHLCV series. Writes go to the source data; reads return the displayed bars, aggregated to the timeframe and clipped by a running replay. Inputs are validated and copied; the chart never mutates them.

set(bars: readonly BarInput[], options?: DataSetOptions): void

Replaces the source bars. Bars must be sorted by strictly ascending time. The view stays where it is, at its zoom: following the latest bar, the new latest bar shows where the old one did; looking back at history, the time at the right edge of the plot stays there, as far as the bars reach.

update(bar: BarInput | readonly BarInput[]): void

Streams source bars: a bar with the time of the last bar replaces it, newer bars are appended. Older bars are rejected; use set() or prepend() for history.

addTrades(trade: TradeInput | readonly TradeInput[]): number

Streams trades, folded into the source bars: a trade in the last bar's period updates it, a later one opens a new bar. Needs a source interval. Trades the calendar drops (outside the sessions) are skipped, and so are late ones, before the last bar or the latest trade, as a stream may deliver after it reconnects; returns how many were applied.

prepend(bars: readonly BarInput[]): number

Adds older source bars before the first one, typically in response to loadMore. Bars at or after the current first bar are ignored. Returns how many bars were inserted.

clear(): void

Removes the bars and ends a running replay; the source interval and timeframe stay.

sourceInterval(): Interval | null

Resolution of the source bars, or null when they are displayed as given.

calendar(): Calendar

The trading calendar the chart builds timeframes with: the calendar option, in the chart's timeZone unless it names one. A new one once the options change; read it when needed.

timeframe(): Interval | null

The displayed timeframe, or null for the source resolution.

setTimeframe(timeframe: IntervalInput | null): void

Displays the source bars aggregated to a coarser timeframe, or at the source resolution with null. Needs a source interval; the timeframe must be built from whole source bars. The view stays where it is in time, as with set().

readonly length: number

Number of displayed bars.

readonly bars: BarsView

The displayed bars as a read-only, columnar view, without copying.

readonly source: BarsView

The source bars as a view: up to the cursor while replaying, at the source interval.

at(index: number): Bar | null
last(): Bar | null
indexOf(time: TimeInput): number

Index of the displayed bar with exactly this time, or -1.

toArray(): Bar[]

DataSetOptionsinterface源码

interface DataSetOptions
interval?: IntervalInput

Resolution of the bars, such as '1m'. Declaring it lets the chart build coarser timeframes and fold trades into bars through the trading calendar. Bars of minutes and hours must start where the calendar starts one, or they throw; bars of days, weeks and months go by their trading date. Without it the bars are displayed as given.

FontOptionsinterface源码

interface FontOptions
family: string
size: number

Axis and label font size in CSS pixels.

GridOptionsinterface源码

interface GridOptions
vertical: boolean
horizontal: boolean
style: LineStyle

HighLowStyleinterface源码

interface HighLowStyle
upColor: string
downColor: string
lineWidth: number

HlcAreaStyleinterface源码

interface HlcAreaStyle
highColor: string
lowColor: string
closeColor: string
highFillColor: string

Between the highs and the closes.

lowFillColor: string

Between the closes and the lows.

lineWidth: number

InteractionOptionsinterface源码

interface InteractionOptions
pan: boolean

Drag the plot to scroll through time.

wheelZoom: boolean

Mouse wheel and trackpad zoom.

pinchZoom: boolean

Two-finger pinch zoom on touch screens.

axisScale: boolean

Drag the axes to scale them; double-click the price axis to reset auto-scale.

kineticScroll: boolean

Keeps scrolling briefly after a quick pan is released.

keyboard: boolean

Arrow keys, +/-, Delete, Escape and undo/redo shortcuts while the chart has focus.

longPressMs: number

Touch press duration that switches a touch into crosshair mode.

touchMagnifier: boolean

Shows a magnifying loupe above the finger while placing anchors or dragging objects by touch.

hitTolerance: number

Pointer distance in CSS pixels that counts as a hit on an object, such as a drawing.

Intervalinterface源码

interface Interval

A bar resolution, such as 5 minutes or 1 day.

readonly unit: IntervalUnit
readonly count: number

A positive integer.

KagiStyleinterface源码

interface KagiStyle

Kagi lines: yang (thick) from where a line passes the last shoulder, yin (thin) under the last waist.

upColor: string

Yang lines.

downColor: string

Yin lines.

upWidth: number
downWidth: number

LabelDragEventinterface源码

interface LabelDragEvent
readonly id: string
readonly phase: DragPhase
readonly position: number

Where along its line the label is at this phase, from 0 at the left of the plot to 1 at its right (where it was for cancel).

readonly initialPosition: number

Where it was before the drag started.

LatestPriceOptionsinterface源码

interface LatestPriceOptions
line: boolean
label: boolean
countdown: boolean

Shows the time left until the current bar closes under the price label, for bars of periods of time, not while replaying, and not once the bar has closed.

style: LineStyle
color: string | null

Color of the line and the label; null follows the latest bar, rising or falling, in the main series' colors.

Layoutinterface源码

interface Layout
width: number
height: number
plotWidth: number
axisWidth: number
leftAxisWidth: number

Width of the left price axis; 0 without one.

panes: PaneLayout[]
separators: SeparatorLayout[]
timeAxis: Rect | null

LegendButtoninterface源码

interface LegendButton

A button of a legend row.

readonly id: string
readonly icon: string

SVG path data drawn in a 24 × 24 box, e.g. from an icon set.

LegendButtonClickEventinterface源码

interface LegendButtonClickEvent

A button of a legend row was clicked.

readonly item: LegendItem
readonly buttonId: string

LegendExtraRowinterface源码

interface LegendExtraRow

A row of the application's own in the legend, such as of what it draws apart from the indicators.

readonly id: string

Names the row in rows, buttons and legendButtonClick, where its item is of kind extra.

readonly type?: string

What it stands for, for rows and buttons to tell rows apart, such as VPVR.

readonly paneId: string

The pane whose legend lists it, after its indicators.

readonly visible: boolean

Hidden, it is listed only if rows asks for it, dimmed.

readonly title: string

What the row says, in the color of the titles.

LegendIteminterface源码

interface LegendItem

A row of the legend: the main series, an indicator, a series added to the chart, or a row of the application's own (extraRows).

readonly kind: 'main' | 'indicator' | 'series' | 'extra'
readonly id: string

The id of the indicator, the series or the application's row; main for the main series.

readonly type: string | null

The indicator's type, or the type the application gave its row; null for the others.

readonly paneId: string
readonly visible: boolean

Hidden indicators and series are listed only if rows asks for them, dimmed.

LegendOptionsinterface源码

interface LegendOptions
visible: boolean

Shows the OHLC values and indicator values of the hovered (or latest) bar in each pane.

rows: ((item: LegendItem) => boolean) | null

Which rows to list, the main series' row of its values among them; null (default) lists the main series and the visible indicators and series. List hidden ones too, and they show dimmed, e.g. for a button that shows them again; leave the main series out to put its values away.

buttons: ((item: LegendItem) => readonly LegendButton[]) | null

Buttons shown after the title of the row under the pointer, such as hide, settings and remove. A click emits legendButtonClick. null (default) shows none.

extraRows: (() => readonly LegendExtraRow[]) | null

Rows of the application's own, listed after the indicators of their pane as rows and buttons have them, such as of what it draws over the bars apart from the indicators, to set or remove it from its buttons. null (default) adds none.

hideValuesOnHover: boolean

Hides the values of the row under the pointer while its buttons show.

top: number

Room above the legend of the main pane, in CSS pixels, for what the application shows over the chart there, such as buttons to trade. Default 0.

LineMarkersStyleinterface源码

interface LineMarkersStyle extends LineSeriesStyle
markerRadius: number

LineSeriesStyleinterface源码

interface LineSeriesStyle
color: string
lineWidth: number
lineStyle: LineStyle

LoadMoreEventinterface源码

interface LoadMoreEvent

The view approaches the oldest bar: load bars before before and pass them to data.prepend().

readonly before: number

The time of the first source bar: older bars go before it.

readonly bars: number

How many more of the bars shown the view wants before the first: those it lacks of loadMoreThreshold, and the room left empty on the left. Bars built from many, as Kagi lines or Renko bricks are, need as many more source bars as each takes.

LogicalRangeinterface源码

interface LogicalRange
from: number

Logical index at the left edge of the plot. Bar i is centered on index i.

to: number

Logical index at the right edge of the plot.

MainSeriesOptionsinterface源码

interface MainSeriesOptions

A built-in series type such as candles, line or area, or a registered custom type.

source: PriceSource

The price a line-like main series plots.

Style overrides keyed by series type, so switching types keeps each type's style.

barColor: ((bar: BarColorContext) => string | null) | null

Colors single bars: return a color, or null for the style's up or down color. Called for every visible bar when the chart repaints; candles, hollow candles, OHLC and high-low bars use it.

ModuleContextinterface源码

interface ModuleContext<Types extends ModuleTypes = ModuleTypes>

What a module made with createModule() gets, beside the chart, as it joins one.

options(): NonNullable<Types['options']>[keyof NonNullable<Types['options']>]

The module's section of the chart's options, as they are now; a module without one throws.

emit<K extends keyof NonNullable<Types['events']> & string>(
  type: K,
  event: NonNullable<Types['events']>[K]
): void

Emits one of the module's events to the listeners chart.on() registers.

keepState<K extends keyof NonNullable<Types['state']> & string>(
  part: ModuleStatePart<K, NonNullable<NonNullable<Types['state']>[K]>>
): void

Keeps a part of the chart's layout in its saved state, which loadState() brings back.

ModuleDefinitioninterface源码

interface ModuleDefinition<
  Types extends ModuleTypes = ModuleTypes,
  Api extends object = NonNullable<Types['api']>
>

A module of an application or another package, as createModule() takes it.

readonly name: string

Unique among the modules of a chart.

readonly options?: ModuleOptionsOf<Types>
install(chart: Chart, context: ModuleContext<Types>): Api | undefined

Joins the chart once the chart and the library's modules given with it are there, before the chart uses its options; returns the namespaces the module adds, or nothing.

ModuleOptionsinterface源码

interface ModuleOptions<Key extends string = string, Section extends object = object>

The options a module adds to the chart's, as a section of them: options.<key>.

readonly key: Key
defaults(): Section

The section's defaults, which the options given are merged over.

validate(section: Section, label: string): void

Throws for an invalid section, as merged; label names it, e.g. options.footprint.

ModuleStatePartinterface源码

interface ModuleStatePart<Key extends string = string, State = unknown>

A part of a chart's saved layout that a module keeps: saveState()[key].

readonly key: Key
save(): State

What the module keeps now, as plain data.

read(saved: unknown, label: string): State

The part of a state to load, checked: throws for an invalid one, and changes nothing.

load(state: State | null): void

Applies a part read gave, or null for a state without one.

ModuleTypesinterface源码

interface ModuleTypes

What a module adds to the chart's types: namespaces of the API, options, events, and what it keeps of the chart's layout in a saved state.

readonly api?: object
readonly options?: object
readonly events?: object
readonly state?: object

ObjectTargetinterface源码

interface ObjectTarget

The object under the pointer when it was clicked.

readonly kind: ObjectKind
readonly id: string
readonly part: string

The part that was hit, such as line, label, handle:0 or button:close.

OhlcStyleinterface源码

interface OhlcStyle
upColor: string
downColor: string
lineWidth: number
ticks: boolean

Draws the open (left) and close (right) ticks.

OptionsChangeEventinterface源码

interface OptionsChangeEvent

Options applied, by applyOptions() or loadState(): those now, and those before.

readonly options: ChartOptions
readonly previous: ChartOptions

Paneinterface源码

interface Pane

A pane as reported by the API.

readonly id: string
readonly title: string
readonly height: number
readonly auto: boolean

Created for an indicator or series and removed with its last occupant.

PaneInputinterface源码

interface PaneInput
id?: string

The chart numbers one, pane-1 on, when it is left out.

title?: string

Shown in the legend.

height?: number

Height in CSS pixels. Ignored for the main pane, which takes the remaining space.

PaneLayoutinterface源码

interface PaneLayout

Rectangles are relative to the left edge of the plots and the top of the chart: the plots start at x 0, and a left price axis lies at negative x. chart.layout() reports them relative to the chart's left edge.

id: string
plot: Rect

The drawing area. Its x is always 0.

axis: Rect

The price axis to the right of the plot.

leftAxis: Rect | null

The price axis to the left of the plot, or null without one.

PaneOptionsinterface源码

interface PaneOptions
defaultHeight: number

Height in CSS pixels of a newly created pane.

minHeight: number

Panes never shrink below this height while resizing.

separatorHeight: number

Height of the draggable separator between panes.

separatorWidth: number

Width in CSS pixels of the line drawn along the separator; 0 draws none.

separatorColor: string | null

Color of that line; null (default) takes the theme's border.

separatorHoverColor: string | null

Color of the line under the pointer and while it is dragged; null (default) takes the theme's crosshair.

PaneResizeEventinterface源码

interface PaneResizeEvent

The user finished resizing a pane by dragging a separator.

readonly paneId: string
readonly height: number

PanesApiinterface源码

interface PanesApi
list(): Pane[]

Panes from top to bottom; the main pane comes first.

get(id: string): Pane | null

The pane of an id, or null.

add(pane: PaneInput): string

Adds a pane below the others and returns its id.

update(id: string, patch: Omit<PaneInput, 'id'>): void

Changes a pane's title or height. Throws for an unknown id.

remove(id: string): void

Removes a pane and its drawings. Remove its indicators and series first; the main pane cannot be removed. Throws for an unknown id.

move(id: string, index: number): void

Moves a pane to position index (the main pane stays at 0).

PerformanceOptionsinterface源码

interface PerformanceOptions
maxPixelRatio: number

Caps the canvas pixel ratio to limit memory use on very dense screens.

maxTrades: number

How many of the latest trades passed to data.addTrades() the chart keeps for bar types built from trades, such as tick bars; older ones go, the bars built from them staying until the bars are rebuilt. 0 keeps none.

PluginHostinterface源码

interface PluginHost

What attach() receives.

readonly chart: Chart
readonly bars: BarsView
readonly source: BarsView
repaint(): void

Repaints the chart in the next frame, e.g. after the plugin's settings changed.

PluginPaintContextinterface源码

interface PluginPaintContext
readonly ctx: CanvasRenderingContext2D

Clipped to the pane's plot and translated to its top left corner, in CSS pixels.

readonly pixelRatio: number
readonly layer: PluginLayer
readonly pane: PluginPane
readonly bars: BarsView

The displayed bars.

readonly source: BarsView

The source bars a running replay has revealed (all of them otherwise).

readonly cutoff: number

Source data after this time is hidden, as a replay hides what has not happened yet; Infinity while the chart shows all of it.

readonly visible: { readonly from: number; readonly to: number } | null

Indices of the displayed bars intersecting the plot, or null.

readonly barSpacing: number
indexToX(index: number): number

X of the center of the bar at a (continuous) index.

xToIndex(x: number): number
timeToX(time: number): number

X of a time, interpolated between bars and extrapolated outside them; NaN without bars.

readonly theme: Theme
readonly font: { readonly family: string; readonly size: number }

PluginPaneinterface源码

interface PluginPane

A pane as a plugin sees it. Coordinates are relative to the pane's plot.

readonly id: string
readonly width: number
readonly height: number
valueToY(value: number): number
yToValue(y: number): number
formatValue(value: number): string

Formats a value like the pane's price axis.

PluginsApiinterface源码

interface PluginsApi
add(plugin: ChartPlugin): void

Attaches a plugin; its name must be unique.

remove(name: string): void

Detaches a plugin.

get(name: string): ChartPlugin | null

The plugin of a name, or null.

list(): ChartPlugin[]

The plugins, in the order they paint.

Pointinterface源码

interface Point
readonly x: number
readonly y: number

PointFigureStyleinterface源码

interface PointFigureStyle

Point & figure columns: X's rising, O's falling, one in each box.

upColor: string
downColor: string
lineWidth: number
widthRatio: number

Width of a box as a fraction of the bar spacing.

box: number | null

The box size; null takes the one the transform building the bars reports.

PriceDragEventinterface源码

interface PriceDragEvent
readonly id: string
readonly phase: DragPhase
readonly price: number

Price at this phase (the restored price for cancel).

readonly initialPrice: number

Price before the drag started.

PriceFormatContextinterface源码

interface PriceFormatContext
paneId: string
precision: number
locale: string

The locale the chart writes in: its locale, or the runtime's.

PriceLineButtoninterface源码

interface PriceLineButton

A button inside an order or alert label. Clicking it emits buttonClick.

id: string
text?: string

Short text such as ✕ or TP.

icon?: string

SVG path data drawn in a 24 × 24 box, e.g. from an icon set.

width?: number

Width in CSS pixels; defaults to fit the content.

PriceRangeinterface源码

interface PriceRange
min: number
max: number

PriceScaleApiinterface源码

interface PriceScaleApi

One price scale of a pane. Coordinates are relative to the chart's top-left corner. A right scale with nothing of its own in a pane where the left one has something shows the left one: setting its range or auto-scaling it changes the left one.

range(): PriceRange | null

Visible value range, or null when nothing is drawn in the pane.

setRange(range: PriceRange): void

Fixes the range and turns auto-scaling off.

autoScale(): void

Turns auto-scaling back on.

isAutoScale(): boolean

The configured mode; percent/indexed/log fall back to normal while their base is unusable.

setMode(mode: PriceScaleMode): void
isInverted(): boolean
setInverted(inverted: boolean): void
margins(): ScaleMargins

Space above and below the auto-scaled data, as fractions of the pane.

setMargins(margins: ScaleMargins | null): void

Sets the margins of this scale, e.g. { top: 0.8, bottom: 0 } for volume at the bottom; null follows priceScale.margins.

priceToY(price: number): number | null
yToPrice(y: number): number | null

PriceScaleOptionsinterface源码

interface PriceScaleOptions
visible: boolean
margins: ScaleMargins

Empty space above and below the auto-scaled range.

precision: number | 'auto'

Decimals of main-series prices, or auto to infer them from the data.

formatter: PriceFormatter | null
minWidth: number

Minimum axis width in CSS pixels; the axis grows to fit its labels.

pinLabels: boolean

Keeps the label of an order or an alert whose line lies above or below the plot at its top or bottom edge, with an arrow, where a click brings the line into view. Otherwise it is out of sight with its line.

Rectinterface源码

interface Rect
x: number
y: number
width: number
height: number

SavedScaleinterface源码

interface SavedScale
readonly id: string
readonly mode: PriceScaleMode
readonly inverted: boolean
readonly margins: ScaleMargins | null
readonly range: PriceRange | null

ScaleMarginsinterface源码

interface ScaleMargins

Empty space above and below the auto-scaled range of a price scale, as fractions of the pane height: each at least 0, and together at most 0.9.

top: number
bottom: number

Selectioninterface源码

interface Selection

The single selected object of a chart.

readonly kind: ObjectKind
readonly id: string

SelectionChangeEventinterface源码

interface SelectionChangeEvent

The user changed the selection by clicking.

readonly selection: Selection | null

SeparatorLayoutinterface源码

interface SeparatorLayout
above: string
below: string
y: number
height: number

Seriesinterface源码

interface Series

A series as reported by the API (without its data).

readonly id: string
readonly type: string
readonly pane: string
readonly scale: string
readonly title: string
readonly visible: boolean
readonly precision: number | null
readonly lastValueLabel: boolean
readonly style: Readonly<Record<string, unknown>>

SeriesApiinterface源码

interface SeriesApi

Additional series aligned to the main bars by time, such as comparison symbols.

set(series: readonly SeriesInput[]): void

Replaces every series, with the points each brings. What reads a series, such as an alert, must find it among them. An invalid input throws and changes nothing.

add(series: SeriesInput): string

Adds a series and returns its id: the one it has, or one the chart numbers for it.

update(id: string, patch: SeriesPatch): void

Throws for an unknown id.

remove(id: string): void

Throws for an unknown id, and while something, such as an alert, reads the series.

clear(): void

Removes every series; throws while something, such as an alert, reads one.

get(id: string): Series | null

The series of an id, or null.

list(): Series[]
setData(id: string, points: readonly SeriesPointInput[]): void
updateData(id: string, point: SeriesPointInput | readonly SeriesPointInput[]): void

Replaces the last point or appends newer points.

prependData(id: string, points: readonly SeriesPointInput[]): void
addTrades(id: string, trades: TradeInput | readonly TradeInput[]): number

Folds trades into a series, such as a symbol compared, as data.addTrades() folds them into the main bars: its bars of the source interval take them, or, for a series of values, a value per source interval takes the price of its last trade; shown in the chart's timeframe. Returns how many it kept: not those outside the sessions, nor late ones.

register<Style extends object>(definition: SeriesTypeDefinition<Style>): void

Adds a series type to this chart, named by its type, for series and the main series.

unregister(type: string): void

Removes a series type. Fails for the types of every chart, while the main series is of it and while series of it are on the chart.

types(): string[]

Every series type the chart has.

definition(type: string): Readonly<SeriesTypeDefinition<object>> | null

The definition of a type, or null for an unknown type.

SeriesInputinterface源码

interface SeriesInput
id?: string

Generated when omitted.

type: string

A series type such as line, area, columns or candles.

pane?: string

main, new (a pane of its own) or the id of an existing pane. Defaults to main.

scale?: string

Price scale in the pane: right (default), left, or any other name for an overlay scale of its own without an axis, e.g. to compare symbols at different prices.

title?: string
visible?: boolean
precision?: number | null

Decimals of its values in the legend and on an axis of its own, such as those of a symbol compared with the bars; null (default) for the main series'.

lastValueLabel?: boolean

A label of its latest value on the axis of its scale, in its color; off by default.

style?: Record<string, unknown>

Style overrides merged on top of the type's theme-derived defaults.

data?: readonly SeriesPointInput[]

SeriesPaintContextinterface源码

interface SeriesPaintContext<Style>
readonly ctx: CanvasRenderingContext2D
readonly pixelRatio: number
readonly width: number

Plot width and height; the context is translated to the plot's top-left corner.

readonly height: number
readonly barSpacing: number
readonly style: Style
readonly points: SeriesPoints
readonly valueToY: (value: number) => number

Converts a data value into a y coordinate of the plot.

readonly bars: BarsView | null

Every bar of an OHLC series, not only those in view, for types whose look follows from the bars before, such as Kagi lines, thick from where they pass the last shoulder. null for value series.

readonly first: number

Position of the first point in the series' data: point i is bar first + i.

readonly transform: Readonly<Record<string, unknown>> | null

What the transform building the main series' bars reports it builds them with (chart.transforms.get().resolved), such as the box size of point & figure columns; null for other series and for bars no transform builds.

SeriesPointsinterface源码

interface SeriesPoints

Render-ready points of a series in plot coordinates, ordered from left to right.

readonly count: number
x(index: number): number

Bar center.

open(index: number): number

y of open, high, low and close for OHLC input.

high(index: number): number
low(index: number): number
close(index: number): number
volume(index: number): number

Volume of OHLC input, as traded (not a coordinate); NaN for value input.

value(index: number): number

y of the value for value input; NaN marks a gap.

isUp(index: number): boolean

Rising point: close ≥ open, or value ≥ the previous value.

color(index: number): string | null

A color chosen for this point (the main series' barColor), or null for the style's.

SeriesStyleMapinterface源码

interface SeriesStyleMap

Resolved style of every series type. Plugins add their own types through declaration merging:

declare module '@kumo-charts/core' {
  interface SeriesStyleMap { renko: { boxColor: string } }
}
candles: CandleStyle
'hollow-candles': CandleStyle
'volume-candles': CandleStyle

Of the chart types module.

'high-low': HighLowStyle
'step-line': LineSeriesStyle
'line-markers': LineMarkersStyle
baseline: BaselineStyle
'hlc-area': HlcAreaStyle
columns: ColumnsStyle

Of the chart types module: the lines of the kagi transform.

'point-figure': PointFigureStyle

Of the chart types module: the columns of the point-figure transform.

SeriesTypeDefinitioninterface源码

interface SeriesTypeDefinition<Style extends object = Record<string, unknown>>

Describes how a series type is drawn. Register custom types with chart.series.register().

readonly type: string

The type series of it name, such as candles.

readonly input: 'ohlc' | 'value'

ohlc series plot open/high/low/close; value series plot one value per point.

defaultStyle(theme: Theme, color: string): Style

Full style derived from the theme; user overrides are merged on top.

extraExtents?(style: Style): readonly number[]

Values the price scale must include in addition to the data, such as a column base.

paint(context: SeriesPaintContext<Style>): void

Themeinterface源码

interface Theme

Colors used across the chart. Series, indicator and object styles derive their defaults from it.

background: string
text: string
textMuted: string
grid: string
border: string
crosshair: string
crosshairLabelBackground: string
crosshairLabelText: string
up: string

Bullish candles, rising values.

down: string

Bearish candles, falling values.

volumeUp: string
volumeDown: string
accent: string

Selection handles and highlighted objects.

palette: readonly [string, ...string[]]

Default colors for drawings, indicators and additional series, in order; at least one.

buy: string
sell: string
alert: string

TimeFormatContextinterface源码

interface TimeFormatContext
kind: 'axis' | 'crosshair'
unit: TimeUnit

For axis labels: the calendar boundary the tick sits on.

locale: string

The locale the chart writes in: its locale, or the runtime's.

timeZone: string

The zone the chart shows times in: its timeZone, or the local one.

TimeRangeinterface源码

interface TimeRange
readonly from: number

Time of the first visible bar.

readonly to: number

Time of the last visible bar.

TimeScaleApiinterface源码

interface TimeScaleApi
visibleRange(): TimeRange | null

Times of the first and last visible bars, or null when none is visible.

setVisibleRange(range: { from: TimeInput; to: TimeInput }): void

Shows the bars between two times.

visibleLogicalRange(): LogicalRange | null

Logical indices at the left and right edges of the plot, or null without bars.

setVisibleLogicalRange(range: LogicalRange): void
scrollToTime(time: TimeInput, align?: ViewAlign): void
scrollToIndex(index: number, align?: ViewAlign): void
scrollToRealTime(): void

Moves back to the latest bar, at the configured right offset.

isFollowing(): boolean

Whether the latest bar is in view, so new bars scroll into view as they arrive.

fitContent(): void
zoomIn(): void

Widens the bars, keeping the latest bar in place while the view follows it, else the bar in the middle of the plot.

zoomOut(): void

Narrows the bars, around the same bar as zoomIn().

barSpacing(): number

Distance between the centers of two bars, in CSS pixels.

setBarSpacing(spacing: number): void
reset(): void

Restores the configured bar spacing and the real-time position.

timeToX(time: TimeInput): number | null

x of the bar at time (interpolated between bars), or null without data.

xToTime(x: number): number | null
indexToX(index: number): number | null
xToIndex(x: number): number | null

Logical index at x; fractional between bar centers.

TimeScaleOptionsinterface源码

interface TimeScaleOptions
visible: boolean
height: number

Axis height in CSS pixels.

barSpacing: number

Initial distance between bars in CSS pixels.

minBarSpacing: number
maxBarSpacing: number
rightOffset: number

Empty space after the latest bar, in CSS pixels, when the chart follows real time.

loadMoreThreshold: number

loadMore fires when fewer than this many bars remain hidden on the left.

formatter: TimeFormatter | null

TradeInputinterface源码

interface TradeInput

A single trade (tick) folded into the source bars by data.addTrades().

price: number
size?: number

Traded quantity added to the bar's volume. Defaults to 0.

side?: TradeSide

The side of the taker: buy for a trade that took an offer, sell for one that took a bid; unknown when left out. Transforms built from the trades receive it.

TransformsApiinterface源码

interface TransformsApi

The transform building the displayed bars from the bars of the timeframe, such as Renko bricks, and the transform types the chart has.

set(transform: BarTransformInput | null): void

Builds the displayed bars with a transform, e.g. { type: 'renko', params: { box: 50 } }, or shows the bars of the timeframe again with null. The view stays where it is in time, as with data.set().

get(): BarTransformState | null

The transform building the displayed bars, or null when they are the bars of the timeframe; resolved holds what it builds with, such as the box size it worked out from the bars.

register<P extends object>(definition: BarTransformDefinition<P>): void

Adds a transform type to this chart, named by its type.

unregister(type: string): void

Removes a transform type. Fails while it builds the displayed bars.

types(): string[]

Every transform type the chart has.

definition(type: string): Readonly<BarTransformDefinition> | null

The definition of a type, or null for an unknown type.

TypesChangeEventinterface源码

interface TypesChangeEvent

A series type, transform type, indicator type or drawing type was registered or unregistered, for lists of the types to follow.

readonly kind: 'series' | 'transform' | 'indicator' | 'drawing'
readonly type: string
readonly registered: boolean

false when it was unregistered.

ValuePointInputinterface源码

interface ValuePointInput

A point of a value series.

value: number | null

null leaves a gap.

VisibleRangeChangeEventinterface源码

interface VisibleRangeChangeEvent
readonly range: TimeRange | null

Times of the first and last visible bars, or null when no bar is visible.

readonly logicalRange: LogicalRange | null

Types

BarChangetype源码

type BarChange =
  /** Every index may have changed (set, prepend or clear). */
  | { readonly kind: 'reset' }
  /** Only bars from `from` (inclusive) to the end changed or were appended. */
  | { readonly kind: 'tail'; readonly from: number }

How the bars changed since a revision a consumer has seen.

CalendarBuckettype源码

type CalendarBucket = (
  time: number,
  interval: Interval,
  fallback: (time: number) => number | null
) => number | null

Overrides the built-in bucketing: returns the start of the bucket time belongs to, or null to drop the time (a holiday or a halt). fallback is the built-in result for the same interval. Buckets must not decrease with time.

CalendarInputtype源码

type CalendarInput = Partial<CalendarOptions>

Options of createCalendar; timeZone defaults to the runtime's local zone.

Charttype源码

type Chart<M extends readonly ChartModule[] = readonly []> = ChartBase<
  ModulesOptions<M>,
  ModulesEvents<M>,
  ModulesState<M>
> &
  ModulesApi<M>

A chart with the modules M, such as Chart<[typeof indicators]>: the core and the namespaces, options and events of the modules. Chart alone is the chart without modules, which every chart is.

ChartAreatype源码

type ChartArea = 'plot' | 'price-axis' | 'time-axis' | 'separator' | 'outside'

The part of the chart under the pointer: the plot of a pane, a price axis, the time axis, the separator between two panes, or none of them, such as the corner below the price axis.

ChartCommandtype源码

type ChartCommand = 'escape' | 'delete' | 'undo' | 'redo' | 'enter' | 'copy' | 'paste'

A command of the keyboard or the context menu that modules run: Escape, Delete, undo, redo, Enter, copy and paste.

ChartOptionsInputtype源码

type ChartOptionsInput = DeepPartial<ChartOptions>

CreateChartOptionstype源码

type CreateChartOptions<M extends readonly ChartModule[]> = DeepPartial<
  ChartOptions & ModulesOptions<M>
> & {
  /** The parts of the chart beyond its core, such as `indicators(allIndicators)`. */
  readonly modules?: M;
}

What createChart() takes: the modules of the chart, and its options.

CrosshairMoveEventtype源码

type CrosshairMoveEvent =
  ({ readonly visible: true } & CrosshairState) | { readonly visible: false }

The pointer moved over the chart (visible: true) or left it.

CrosshairPriceLinestype源码

type CrosshairPriceLines = (price: number, paneId: string) => readonly string[]

The lines under the crosshair's price label (crosshair.labels.priceLines), of the price at the pointer in a pane.

DeepPartialtype源码

type DeepPartial<T> = T extends (...args: never[]) => unknown
  ? T
  : T extends readonly unknown[]
    ? T
    : T extends object
      ? { [K in keyof T]?: DeepPartial<T[K]> }
      : T

Recursively optional version of T. Functions and arrays are replaced, never merged.

DragPhasetype源码

type DragPhase = 'start' | 'move' | 'end' | 'cancel'

IntervalInputtype源码

type IntervalInput = Interval | string

An Interval or its shorthand <count><unit>: s second, m minute, h hour, D day, W week, M month (H, d and w work too; only m and M differ by case). The count may be omitted: 'D' is '1D'.

IntervalUnittype源码

type IntervalUnit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month'

LineStyletype源码

type LineStyle = (typeof LINE_STYLES)[number]

MarkerShapetype源码

type MarkerShape =
  'arrow-up' | 'arrow-down' | 'triangle-up' | 'triangle-down' | 'circle' | 'square'

Shapes of markers: on the chart's markers and on indicator values.

ModuleOptionsOftype源码

type ModuleOptionsOf<Types extends ModuleTypes> = {
  [K in keyof NonNullable<Types['options']> & string]: ModuleOptions<
    K,
    NonNullable<Types['options']>[K] & object
  >;
}[keyof NonNullable<Types['options']> & string]

The section of options a module of Types may add.

ModulesApitype源码

type ModulesApi<M extends readonly ChartModule[]> =
  ModulesTypes<M> extends { readonly api: infer A } ? A : unknown

The namespaces the modules add to the chart.

ModulesEventstype源码

type ModulesEvents<M extends readonly ChartModule[]> =
  ModulesTypes<M> extends { readonly events: infer E } ? E : unknown

The events the modules add to the chart's.

ModulesOptionstype源码

type ModulesOptions<M extends readonly ChartModule[]> =
  ModulesTypes<M> extends { readonly options: infer O } ? O : unknown

The options the modules add to the chart's.

ModulesStatetype源码

type ModulesState<M extends readonly ChartModule[]> =
  ModulesTypes<M> extends { readonly state: infer S } ? S : unknown

What the modules keep in the chart's saved state.

ModulesTypestype源码

type ModulesTypes<M extends readonly ChartModule[]> = (
  NonNullable<M[number]['~types']> extends infer T
    ? T extends unknown
      ? (value: T) => void
      : never
    : never
) extends (value: infer I) => void
  ? I
  : never

What the modules add to the chart, merged: their API, options, events and saved state. The union of what each adds becomes an intersection through the parameter of a function type.

ObjectKindtype源码

type ObjectKind = 'drawing' | 'order' | 'alert' | 'marker'

PluginLayertype源码

type PluginLayer = 'below' | 'above'

Where a plugin paints: under the series (after the grid) or over them (under the objects).

PriceFormattertype源码

type PriceFormatter = (value: number, context: PriceFormatContext) => string

Formats a price label. value is already converted for percent/indexed scales.

PriceScaleModetype源码

type PriceScaleMode = 'normal' | 'log' | 'percent' | 'indexed'

PriceSourcetype源码

type PriceSource = (typeof PRICE_SOURCES)[number]

Price fields a line-like series or an indicator can read from a bar.

SeriesPatchtype源码

type SeriesPatch = Pick<
  SeriesInput,
  'title' | 'visible' | 'precision' | 'lastValueLabel' | 'style' | 'scale'
>

What series.update() changes of a series.

SeriesPointInputtype源码

type SeriesPointInput = ValuePointInput | BarInput

SeriesStyleOverridestype源码

type SeriesStyleOverrides = { [K in SeriesType]?: Partial<SeriesStyleMap[K]> | null }

Partial style overrides keyed by series type; null drops those of a type.

SeriesTypetype源码

type SeriesType = keyof SeriesStyleMap

TextOverridestype源码

type TextOverrides<Texts> = { [K in keyof Texts]: Texts[K] | null }

Words that replace those a chart or a module paints, each null while it is not replaced.

TimeFormattertype源码

type TimeFormatter = (time: number, context: TimeFormatContext) => string

Formats a time label. kind tells where the label is shown.

TimeInputtype源码

type TimeInput = number | string | Date

A point in time: epoch milliseconds, an ISO-8601 string or a Date.

TimeUnittype源码

type TimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'

TradeSidetype源码

type TradeSide = 'buy' | 'sell'

The side of the taker of a trade.

Unsubscribetype源码

type Unsubscribe = () => void

ValueSourcetype源码

type ValueSource =
  | { readonly kind: 'price'; readonly field?: PriceSource }
  /** An output of an indicator; `key` defaults to its first output. */
  | { readonly kind: 'indicator'; readonly id: string; readonly key?: string }
  | { readonly kind: 'series'; readonly id: string }
  /** A line of a drawing at each bar, e.g. a trend line; `level` defaults to its first line. */
  | { readonly kind: 'drawing'; readonly id: string; readonly level?: string }

A value at each bar, which alerts watch and mainSeries.barColor reads.

ViewAligntype源码

type ViewAlign = 'left' | 'center' | 'right'

Variables

darkThemevariable源码

const darkTheme: Theme

lightThemevariable源码

const lightTheme: Theme

LINE_STYLESvariable源码

const LINE_STYLES: readonly ["solid", "dashed", "dotted"]

The ways a line is stroked.

PRICE_SOURCESvariable源码

const PRICE_SOURCES: readonly ["open", "high", "low", "close", "hl2", "hlc3", "ohlc4"]

The prices a bar gives, in the order forms list them.

↑↓ 选择 · Enter 打开 · Esc 关闭