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
}
) => Chart
Initialize a chart and return the chart instance.
ds
container, can be dom element or element id.options
optional configuration items.layout
custom layout,content
andoptions
refer to the input parametersvalue
andoptions
in the instance api createIndicator. ^9.6.0locale
language, built-in support forzh-CN
anden-US
.timezone
time zone name, such as 'Asia/Shanghai', if not set, it will automatically get the local time zone, please refer to timezone list.styles
It 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.customApi
customize some APIs.formatDate
formats a date.formatBigNumber
format big numbers, such as 1000 into 1k, 1000000 into 1M, etc.\
thousandsSeparator
thousands separatordecimalFoldThreshold
decimal fold threshold ^9.8.0
dispose(dcs) โ
(dcs: HTMLElement | Chart | string) => void
Destroys a chart, once destroyed the chart will no longer be available.
dcs
can 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
}
) => void
Add a localization language. Charts have built-in zh-CN
and en-US
.
locale
language namelocales
language 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
) => void
Add a style configuration.
name
style namestyles
style 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
}
) => void
Add a figure.
figure
Basic figure information, see figure for detailsname
name, unique identifierdraw
drawing methodcheckEventOn
checks if the event is on the graph
getSupportedFigures() โ
() => string[]
Get the basic graph type supported by the graph.
getFigureClass(name) โ
(name: string) => Figure
Get graph class.
name
name
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
}
) => void
Add a technical indicator.
indicator
technical indicator informationname
indicator name, unique identifier for creation and operationshortName
short name for displayprecision
precisioncalcParams
calculation parametersshouldOhlc
needs ohlc auxiliary graphicsshouldFormatBigNumber
should format large numbers. For example, 1000 is converted to 1k, 1000000 is converted to 1M, etc.visible
visible or notextendData
extended dataseries
indicator series, options are 'normal', 'price' and 'volume'figures
graphics configurationminValue
specifies the minimum valuemaxValue
specifies the maximum valuestyles
stylescalc
calculation methodregenerateFigures
method to regenerate figure informationcreateTooltipDataSource
method to create custom tip informationdraw
custom 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
}
) => void
Add a overlay.
overlay
overlay information, see overlay for detailsname
overlay name, unique identifier for creationtotalStep
total implementation stepslock
is locked to prevent draggingvisible
visible or notzLevel
draw levelneedDefaultPointFigure
needs the default point figureneedDefaultXAxisFigure
needs the default x-axis figureneedDefaultYAxisFigure
needs the default y-axis figuremode
mode, options are 'normal', 'weak_magnet' and 'strong_magnet'modeSensitivity
mode sensitivity, only valid when mode is weak_magnet ^9.5.0points
point informationextendData
extended datastyles
stylescreatePointFigures
creates figures corresponding to pointscreateXAxisFigures
creates figures on the x-axiscreateYAxisFigures
creates figures on the y-axisperformEventPressedMove
special handling method for press and move eventperformEventMoveForDrawing
special processing method during moving eventonDrawStart
start drawing eventonDrawing
drawing eventonDrawEnd
draw end eventonClick
click eventonDoubleClick
double click event ^9.5.0onRightClick
right click eventonPressedMoveStart
press start move eventonPressedMoving
Press and move eventonPressedMoveEnd
Press and move end eventonMouseEnter
mouse enter eventonMouseLeave
mouse out eventonRemoved
delete eventonSelected
selected eventonDeselected
deselected 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
}>
}
) => void
Add custom x-axis.
axis
axis infoname
axis namecreateTicks
create ticks
registerYAxis(axis) ^9.8.0 โ
(
axis: {
name: string
createTicks: (params: object) => Array<{
coord: number
value: number | string
text: string
}>
}
) => void
Add custom y-axis.
axis
axis infoname
axis namecreateTicks
create ticks
version() โ
() => string
Get the current version number of the chart.
utils โ
A collection of helper methods.
utils.clone(target) โ
(target: any) => any
deep copy.
utils.merge(target, source) โ
(target: object, source: object) => void
Merge one object into another.
utils.isString(value) โ
(value: any) => boolean
Checks if a value is a string.
utils.isNumber(value) โ
(value: any) => boolean
Checks if a value is a number.
utils.isValid(value) โ
(value: any) => boolean
Checks if a value is valid.
utils.isObject(value) โ
(value: any) => boolean
Checks if a value is an object.
utils.isFunction(value) โ
(value: any) => boolean
Checks if a value is a method.
utils.isBoolean(value) โ
(value: any) => boolean
Checks if a value is a bool value.
utils.formatValue(value, key, defaultValue) โ
(data: any, key: string, defaultValue?: any) => any
Get 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) => string
Formatting precision.
utils.formatBigNumber(value) โ
(value: string | number) => string
Format large numbers, such as 1000 into 1k, 1000000 into 1M, etc.
utils.formatDate(dateTimeFormat, timestamp, format) โ
(dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string) => string
Format date. format
, such as 'YYYY-MM-DD HH:mm:ss'.
utils.formatThousands(value, sign) โ
(value: string | number, sign: string) => string
Format thousands separator.
utils.formatFoldDecimal(value, threshold) ^9.8.0 โ
(value: string | number, threshold: number) => string
Format fold decimal.
utils.calcTextWidth(text, size, weight, family) ^9.3.0 โ
(text: string, size?: number, weight?: string | number, family?: string) => number
Calculate 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
}
) => number
Get 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
}
) => number
Get 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
}
) => boolean
Check whether a certain coordinate point is on the arc.
coordinate
coordinate point informationarc
arc parameterx
the x-axis value of the center of the circley
the y-axis value of the center of the circler
radiusstartAngle
start angleendAngle
end angle
utils.checkCoordinateOnCircle(coordinate, circle) โ
(
coordinate: {
x: number
y: number
},
circle: {
x: number
y: number
r: number
}
) => boolean
Checks whether a certain coordinate point is on a circle.
coordinate
coordinate point informationcircle
circle parameterx
the x-axis value of the center of the circley
the y-axis value of the center of the circler
radius
utils.checkCoordinateOnLine(coordinate, line) โ
(
coordinate: {
x: number
y: number
},
line: {
coordinates: Array<{
x: number
y: number
}>
}
) => boolean
Check 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
}>
}
) => boolean
Checks 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
}
) => boolean
Checks whether a certain coordinate point is on a rectangle.
coordinate
coordinate point informationrect
rectangle parameterx
starting point x-axis valuey
starting point y-axis valuewidth
widthheight
height
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
}
) => boolean
Check if a certain coordinate point is on the text.
coordinate
coordinate point informationtext
text parameterx
starting point x-axis valuey
starting point y-axis valuetext
text contentalign
horizontal alignmentbaseline
vertical alignment
styles
stylescolor
colorsize
sizefamily
fontweight
weight
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[]
}
) => void
Draw an arc.
ctx
canvas contextarc
arc parameterx
the x-axis value of the center of the circley
the y-axis value of the center of the circler
radiusstartAngle
starting angleendAngle
end angle
styles
stylesstyle
arc stylesize
thicknesscolor
colordashedValue
Dashed 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>
}
) => void
Draw the circle.
ctx
canvas contextcircle
circle parameterx
the x-axis value of the center of the circley
the y-axis value of the center of the circler
radius
styles
stylesstyle
stylecolor
colorborderColor
border colorborderSize
border thicknessborderStyle
border styleborderDashedValue
border 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[]
}
) => void
Draw the line.
ctx
canvas contextline
line parameterstyles
stylesstyle
line stylesize
thicknesscolor
colordashedValue
Dashed 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>
}
) => void
Draw the polygon.
ctx
canvas contextpolygon
polygon parameterstyles
stylesstyle
stylecolor
colorborderColor
border colorborderSize
border thicknessborderStyle
border styleborderDashedValue
border 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
}
) => void
Draw a rectangle.
ctx
canvas contextrect
rectangle parameterx
starting point x-axis valuey
starting point y-axis valuewidth
widthheight
height
styles
stylesstyle
stylecolor
colorborderColor
border colorborderSize
border thicknessborderStyle
border styleborderDashedValue
border dashed line parameter valueborderRadius
border 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
}
) => void
Draw text.
ctx
canvas contextrectText
text parameterx
starting point x-axis valuey
starting point y-axis valuetext
text contentwidth
widthheight
heightalign
horizontal alignmentbaseline
vertical alignment
styles
stylesstyle
stylecolor
colorsize
sizefamily
fontweight
weightpaddingLeft
left padding,paddingTop
top padding,paddingRight
right padding,paddingBottom
bottom padding,borderColor
border colorborderSize
border thicknessborderStyle
border styleborderRadius
border radius sizeborderDashedValue
border dashed line parameter valuebackgroundColor
background 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.