Chart API â
init(ds, options) â
(
ds: string | HTMLElement,
options?: {
layout?: Array<{
type: 'candle' | 'indicator' | 'xAxis'
content: Array<Indicator | string>
options: {
id?: string
height?: number
minHeight?: number
dragEnabled?: boolean
position?: 'top' | 'bottom'
gap?: {
top?: number
bottom?: number
}
axisOptions?: {
name?: string
scrollZoomEnabled?: boolean
}
}
}>
locale?: string
timezone?: string
styles?: string | object
customApi?: {
formatDate?: (dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string, type: number) => string
formatBigNumber?: (value: string | number) => string
}
thousandsSeparator?: string
decimalFoldThreshold?: number
}
) => ChartInitialize a chart and return the chart instance.
dscontainer, can be dom element or element id.optionsoptional configuration items.layoutcustom layout,contentandoptionsrefer to the input parametersvalueandoptionsin the instance api createIndicator. ^9.6.0localelanguage, built-in support forzh-CNanden-US.timezonetime zone name, such as 'Asia/Shanghai', if not set, it will automatically get the local time zone, please refer to timezone list.stylesIt can be the style name registered throughklinecharts.registerStyles, or it can be an object, a list of styles, see styles for details, and supports increments.customApicustomize some APIs.formatDateformats a date.formatBigNumberformat big numbers, such as 1000 into 1k, 1000000 into 1M, etc.\
thousandsSeparatorthousands separatordecimalFoldThresholddecimal fold threshold ^9.8.0
dispose(dcs) â
(dcs: HTMLElement | Chart | string) => voidDestroys a chart, once destroyed the chart will no longer be available.
dcscan be a dom element, element id or chart instance.
registerLocale(locale, locales) â
(
locale: string,
locales: {
time: string
open: string
high: string
low: string
close: string
volume: string
}
) => voidAdd a localization language. Charts have built-in zh-CN and en-US.
localelanguage namelocaleslanguage configuration
getOverlayClass() â
(name: string) => Nullable<OverlayConstructor>Get chart's overlay attributes by overlay name.
getSupportedLocales() â
() => string[]Get the localized language types supported by the chart.
registerStyles(name, styles) â
(
name: string,
styles: object
) => voidAdd a style configuration.
namestyle namestylesstyle configuration, refer to style for the type, support increment.
registerFigure(figure) â
(
figure: {
name: string
draw: (ctx: CanvasRenderingContext2D, attrs: any, styles: object) => void
checkEventOn: (coordinate: Coordinate, attrs: any, styles: object) => boolean
}
) => voidAdd a figure.
figureBasic figure information, see figure for detailsnamename, unique identifierdrawdrawing methodcheckEventOnchecks if the event is on the graph
getSupportedFigures() â
() => string[]Get the basic graph type supported by the graph.
getFigureClass(name) â
(name: string) => FigureGet graph class.
namename
registerIndicator(indicator) â
(
indicator: {
name: string
shortName?: string
precision?: number
calcParams?: any[]
shouldOhlc?: boolean
shouldFormatBigNumber?: boolean
visible?: boolean
extendData?: any
series?: 'normal' | 'price' | 'volume'
figures?: Array<{
key: string
title?: string
type?: string
baseValue?: number
attrs?: ({
data: object
coordinate: object
bounding: object
barSpace: object
xAxis: object
yAxis: object
}) => object
styles?: (
data: object,
indicator: object,
defaultStyles: object
) => object
}>
minValue?: number
maxValue?: number
styles?: object
calc: (dataList: KLineData[], indicator: object) => Promise<object[]> | object[]
regenerateFigures?: (calcParms: any[]) => Array<{
key: string
title?: string
type?: string
baseValue?: number
styles?: (
data: object
indicator: object
defaultStyles: object
) => object
attrs: (
coordinate: object
bounding: Bounding
barSpace: BarSpace
xAxis: XAxis
yAxis: YAxis
) => object
}>
createTooltipDataSource?: (params: object) => {
name?: string
calcParamsText?: string
values?: Array<{
title: string | {
text: string
color: string
}
value: string | {
text: string
color: string
}
}>
}
draw?: (params: object) => boolean
}
) => voidAdd a technical indicator.
indicatortechnical indicator informationnameindicator name, unique identifier for creation and operationshortNameshort name for displayprecisionprecisioncalcParamscalculation parametersshouldOhlcneeds ohlc auxiliary graphicsshouldFormatBigNumbershould format large numbers. For example, 1000 is converted to 1k, 1000000 is converted to 1M, etc.visiblevisible or notextendDataextended dataseriesindicator series, options are 'normal', 'price' and 'volume'figuresgraphics configurationminValuespecifies the minimum valuemaxValuespecifies the maximum valuestylesstylescalccalculation methodregenerateFiguresmethod to regenerate figure informationcreateTooltipDataSourcemethod to create custom tip informationdrawcustom drawing method
getSupportedIndicators() â
() => string[]Get technical indicators for chart support.
registerOverlay(overlay) â
(
overlay: {
name: string
totalStep?: number
lock?: boolean
visible?: boolean
zLevel?: number
needDefaultPointFigure?: boolean
needDefaultXAxisFigure?: boolean
needDefaultYAxisFigure?: boolean
mode?: 'normal' | 'weak_magnet' | 'strong_magnet'
modeSensitivity?: number
points?: Array<{ timestamp: number, dataIndex?: number, value?: number }>
extendData?: any
styles?: object
createPointFigures?: (params: object) => {
key?: string
type: string
attrs: any | any[]
styles?: any
ignoreEvent?: boolean | OverlayFigureIgnoreEventType[]
} | Array<{
key?: string
type: string
attrs: any | any[]
styles?: any
ignoreEvent?: boolean | OverlayFigureIgnoreEventType[]
}>
createXAxisFigures?: (params: object) => {
key?: string
type: string
attrs: any | any[]
styles?: any
ignoreEvent?: boolean | OverlayFigureIgnoreEventType[]
} | Array<{
key?: string,
type: string,
attrs: any | any[]
styles?: any
ignoreEvent?: boolean | OverlayFigureIgnoreEventType[]
}>
createYAxisFigures?: (params: object) => {
key?: string
type: string
attrs: any | any[]
styles?: any
ignoreEvent?: boolean | OverlayFigureIgnoreEventType[]
} | Array<{
key?: string
type: string
attrs: any | any[]
styles?: any
ignoreEvent?: boolean | OverlayFigureIgnoreEventType[]
}>
performEventPressedMove?: (params: object) => void
performEventMoveForDrawing?: (params: object) => void
onDrawStart?: (event: object) => boolean
onDrawing?: (event: object) => boolean
onDrawEnd?: (event: object) => boolean
onClick?: (event: object) => boolean
onDoubleClick?: (event: object) => boolean
onRightClick?: (event: object) => boolean
onPressedMoveStart?: (event: object) => boolean
onPressedMoving?: (event: object) => boolean
onPressedMoveEnd?: (event: object) => boolean,
onMouseEnter?: (event: object) => boolean
onMouseLeave?: (event: object) => boolean
onRemoved?: (event: object) => boolean
onSelected?: (event: object) => boolean
onDeselected?: (event: object) => boolean
}
) => voidAdd a overlay.
overlayoverlay information, see overlay for detailsnameoverlay name, unique identifier for creationtotalSteptotal implementation stepslockis locked to prevent draggingvisiblevisible or notzLeveldraw levelneedDefaultPointFigureneeds the default point figureneedDefaultXAxisFigureneeds the default x-axis figureneedDefaultYAxisFigureneeds the default y-axis figuremodemode, options are 'normal', 'weak_magnet' and 'strong_magnet'modeSensitivitymode sensitivity, only valid when mode is weak_magnet ^9.5.0pointspoint informationextendDataextended datastylesstylescreatePointFigurescreates figures corresponding to pointscreateXAxisFigurescreates figures on the x-axiscreateYAxisFigurescreates figures on the y-axisperformEventPressedMovespecial handling method for press and move eventperformEventMoveForDrawingspecial processing method during moving eventonDrawStartstart drawing eventonDrawingdrawing eventonDrawEnddraw end eventonClickclick eventonDoubleClickdouble click event ^9.5.0onRightClickright click eventonPressedMoveStartpress start move eventonPressedMovingPress and move eventonPressedMoveEndPress and move end eventonMouseEntermouse enter eventonMouseLeavemouse out eventonRemoveddelete eventonSelectedselected eventonDeselecteddeselected event
getSupportedOverlays() â
() => string[]Get overlays for chart support.
registerXAxis(axis) ^9.8.0 â
(
axis: {
name: string
createTicks: (params: object) => Array<{
coord: number
value: number | string
text: string
}>
}
) => voidAdd custom x-axis.
axisaxis infonameaxis namecreateTickscreate ticks
registerYAxis(axis) ^9.8.0 â
(
axis: {
name: string
createTicks: (params: object) => Array<{
coord: number
value: number | string
text: string
}>
}
) => voidAdd custom y-axis.
axisaxis infonameaxis namecreateTickscreate ticks
version() â
() => stringGet the current version number of the chart.
utils â
A collection of helper methods.
utils.clone(target) â
(target: any) => anydeep copy.
utils.merge(target, source) â
(target: object, source: object) => voidMerge one object into another.
utils.isString(value) â
(value: any) => booleanChecks if a value is a string.
utils.isNumber(value) â
(value: any) => booleanChecks if a value is a number.
utils.isValid(value) â
(value: any) => booleanChecks if a value is valid.
utils.isObject(value) â
(value: any) => booleanChecks if a value is an object.
utils.isFunction(value) â
(value: any) => booleanChecks if a value is a method.
utils.isBoolean(value) â
(value: any) => booleanChecks if a value is a bool value.
utils.formatValue(value, key, defaultValue) â
(data: any, key: string, defaultValue?: any) => anyGet the corresponding value from a certain value, support nesting, such as const o = { a: { b: { c: 1 } } }, formatValue(o, 'a.b.c') takes the value of c .
utils.formatPrecision(value) â
(value: string | number, precision?: number) => stringFormatting precision.
utils.formatBigNumber(value) â
(value: string | number) => stringFormat large numbers, such as 1000 into 1k, 1000000 into 1M, etc.
utils.formatDate(dateTimeFormat, timestamp, format) â
(dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string) => stringFormat date. format, such as 'YYYY-MM-DD HH:mm:ss'.
utils.formatThousands(value, sign) â
(value: string | number, sign: string) => stringFormat thousands separator.
utils.formatFoldDecimal(value, threshold) ^9.8.0 â
(value: string | number, threshold: number) => stringFormat fold decimal.
utils.calcTextWidth(text, size, weight, family) ^9.3.0 â
(text: string, size?: number, weight?: string | number, family?: string) => numberCalculate text width.
utils.getLinearSlopeIntercept(coordinate1, coordinate2) â
(
coordinate1: {
x: number
y: number
},
coordinate2: {
x: number
y: number
}
) => []According to two coordinate points, get the slope and constant term of the line composed of points, namely k and b in y = kx + b.
utils.getLinearYFromCoordinates(coordinate1, coordinate2, targetCoordinate) â
(
coordinate1: {
x: number
y: number
},
coordinate2: {
x: number
y: number
},
targetCoordinate: {
x: number
y: number
}
) => numberGet the y-axis coordinate value of a point on the line formed by two other coordinate points.
utils.getLinearYFromSlopeIntercept(kb, targetCoordinate) â
(
kb: Array<number>,
targetCoordinate: {
x: number
y: number
}
) => numberGet the y-coordinate value of a point on the line formed by the slope and the constant term.
utils.checkCoordinateOnArc(coordinate, arc) â
(
coordinate: {
x: number
y: number
},
arc: {
x: number
y: number
r: number
startAngle: number
endAngle: number
}
) => booleanCheck whether a certain coordinate point is on the arc.
coordinatecoordinate point informationarcarc parameterxthe x-axis value of the center of the circleythe y-axis value of the center of the circlerradiusstartAnglestart angleendAngleend angle
utils.checkCoordinateOnCircle(coordinate, circle) â
(
coordinate: {
x: number
y: number
},
circle: {
x: number
y: number
r: number
}
) => booleanChecks whether a certain coordinate point is on a circle.
coordinatecoordinate point informationcirclecircle parameterxthe x-axis value of the center of the circleythe y-axis value of the center of the circlerradius
utils.checkCoordinateOnLine(coordinate, line) â
(
coordinate: {
x: number
y: number
},
line: {
coordinates: Array<{
x: number
y: number
}>
}
) => booleanCheck if a certain coordinate point is on the line.
utils.checkCoordinateOnPolygon(coordinate, polygon) â
(
coordinate: {
x: number
y: number
},
polygon: {
coordinates: Array<{
x: number
y: number
}>
}
) => booleanChecks whether a certain coordinate point is on a polygon.
utils.checkCoordinateOnRect(coordinate, rect) â
(
coordinate: {
x: number
y: number
},
rect: {
x: number
y: number
width: number
height: number
}
) => booleanChecks whether a certain coordinate point is on a rectangle.
coordinatecoordinate point informationrectrectangle parameterxstarting point x-axis valueystarting point y-axis valuewidthwidthheightheight
utils.checkCoordinateOnText(coordinate, text, styles) â
(
coordinate: {
x: number
y: number
},
text: {
x: number
y: number
text: any
align?: 'center' | 'end' | 'left' | 'right' | 'start'
baseline?: 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top'
},
styles: {
color?: string
size?: number
family?: string
weight?: number | string
}
) => booleanCheck if a certain coordinate point is on the text.
coordinatecoordinate point informationtexttext parameterxstarting point x-axis valueystarting point y-axis valuetexttext contentalignhorizontal alignmentbaselinevertical alignment
stylesstylescolorcolorsizesizefamilyfontweightweight
utils.drawArc(ctx, arc, styles) â
(
ctx: CanvasRenderingContext2D,
arc: {
x: number
y: number
r: number
startAngle: number
endAngle: number
},
styles: {
style?: 'solid' | 'dashed'
size?: number
color?: string
dashedValue?: number[]
}
) => voidDraw an arc.
ctxcanvas contextarcarc parameterxthe x-axis value of the center of the circleythe y-axis value of the center of the circlerradiusstartAnglestarting angleendAngleend angle
stylesstylesstylearc stylesizethicknesscolorcolordashedValueDashed parameter value
utils.drawCircle(ctx, circle, styles) â
(
ctx: CanvasRenderingContext2D,
circle: {
x: number
y: number
r: number
},
styles: {
style?: 'stroke' | 'fill' | 'stroke_fill'
color?: string | CanvasGradient
borderColor?: string
borderSize?: number
borderStyle?: 'solid' | 'dashed'
borderDashedValue?: Array<number>
}
) => voidDraw the circle.
ctxcanvas contextcirclecircle parameterxthe x-axis value of the center of the circleythe y-axis value of the center of the circlerradius
stylesstylesstylestylecolorcolorborderColorborder colorborderSizeborder thicknessborderStyleborder styleborderDashedValueborder dashed line parameter value
utils.drawLine(ctx, line, styles) â
(
ctx: CanvasRenderingContext2D,
line: {
coordinates: Array<{
x: number
y: number
}>
},
styles: {
style?: 'solid' | 'dashed'
size?: number
color?: string
dashedValue?: number[]
}
) => voidDraw the line.
ctxcanvas contextlineline parameterstylesstylesstyleline stylesizethicknesscolorcolordashedValueDashed parameter value
utils.drawPolygon(ctx, polygon, styles) â
(
ctx: CanvasRenderingContext2D,
polygon: {
coordinates: Array<{
x: number
y: number
}>
},
styles: {
style?: 'stroke' | 'fill' | 'stroke_fill'
color?: string | CanvasGradient
borderColor?: string
borderSize?: number
borderStyle?: 'solid' | 'dashed'
borderDashedValue?: Array<number>
}
) => voidDraw the polygon.
ctxcanvas contextpolygonpolygon parameterstylesstylesstylestylecolorcolorborderColorborder colorborderSizeborder thicknessborderStyleborder styleborderDashedValueborder dashed line parameter value
utils.drawRect(ctx, rect, styles) â
(
ctx: CanvasRenderingContext2D,
rect: {
x: number
y: number
width: number
height: number
},
styles: {
style?: 'stroke' | 'fill' | 'stroke_fill'
color?: string | CanvasGradient
borderColor?: string
borderSize?: number
borderStyle?: 'solid' | 'dashed'
borderDashedValue?: Array<number>
borderRadius?: number
}
) => voidDraw a rectangle.
ctxcanvas contextrectrectangle parameterxstarting point x-axis valueystarting point y-axis valuewidthwidthheightheight
stylesstylesstylestylecolorcolorborderColorborder colorborderSizeborder thicknessborderStyleborder styleborderDashedValueborder dashed line parameter valueborderRadiusborder radius
utils.drawRectText(ctx, rectText, styles) â
(
ctx: CanvasRenderingContext2D,
rectText: {
x: number
y: number
text: any
width?: number
height?: number
align?: 'center' | 'end' | 'left' | 'right' | 'start'
baseline?: 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top'
},
styles: {
style?: 'stroke' | 'fill' | 'stroke_fill'
color?: string
size?: number
family?: string
weight?: number | string
paddingLeft?: number
paddingTop?: number
paddingRight?: number
paddingBottom?: number
borderStyle?: 'solid' | 'dashed'
borderDashedValue?: number[]
borderSize?: number
borderColor?: string
borderRadius?: number
backgroundColor?: string
}
) => voidDraw text.
ctxcanvas contextrectTexttext parameterxstarting point x-axis valueystarting point y-axis valuetexttext contentwidthwidthheightheightalignhorizontal alignmentbaselinevertical alignment
stylesstylesstylestylecolorcolorsizesizefamilyfontweightweightpaddingLeftleft padding,paddingToptop padding,paddingRightright padding,paddingBottombottom padding,borderColorborder colorborderSizeborder thicknessborderStyleborder styleborderRadiusborder radius sizeborderDashedValueborder dashed line parameter valuebackgroundColorbackground color
utils.drawRectText(ctx, rectText, styles) â
Same as utils.drawRectText(ctx, text, styles), it is deprecated and will be deleted after v10. Please use utils.drawRectText(ctx, text, styles) instead.