Kumo Charts

@kumo-charts/react

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

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

Functions

useKumoChartfunction源码

function useKumoChart<const M extends readonly ChartModule[] = readonly []>(
  options?: CreateChartOptions<M>
): [ref: (element: HTMLElement | null) => void, chart: Chart<M> | null]

Creates a chart in the element that receives the returned ref, with the modules of the options as they are then, and destroys it when the element goes away. The other options are applied with chart.applyOptions() whenever a new object is passed, so keep them stable (a module constant or useMemo).

const [ref, chart] = useKumoChart({ modules: [indicators(allIndicators)] });
useEffect(() => chart?.data.set(bars), [chart, bars]);
return <div ref={ref} style={{ height: 480 }} />;

Interfaces

KumoChartPropsinterface源码

interface KumoChartProps extends KumoChartEventHandlers
modules?: readonly ChartModule[]

The chart's modules, such as [indicators(allIndicators)], read when it is created.

options?: ChartOptionsInput & Readonly<Record<string, unknown>>

Applied with chart.applyOptions() whenever a new object is passed, the options of the modules too.

data?: readonly BarInput[]

Replaces all bars when a new array or interval is passed.

interval?: IntervalInput

Resolution of data, such as '1m'; needed for timeframe and chart.data.addTrades().

timeframe?: IntervalInput | null

The displayed timeframe, such as '15m'; null shows the source resolution.

transform?: BarTransformInput | null

Builds the displayed bars, e.g. { type: 'renko' }; null shows the timeframe's bars.

orders?: readonly OrderInput[]

Needs the orders module.

markers?: readonly MarkerInput[]

Needs the markers module.

alerts?: readonly AlertInput[]

Needs the alerts module.

className?: string
style?: CSSProperties

Merged over the default width: 100%; height: 100%.

onReady?: (chart: Chart) => void

Called once the chart is created, after the props above were applied.

Types

KumoChartEventHandlerstype源码

type KumoChartEventHandlers = {
  [K in KumoChartEventName as `on${Capitalize<K>}`]?: (event: KumoChartEventMap[K]) => void;
}

One optional on* prop per event of the chart and its modules, e.g. onCrosshairMove or onOrderDrag.

KumoChartEventMaptype源码

type KumoChartEventMap = AllEventMap

The events of the chart and of its modules; those of a module the chart lacks never fire.

KumoChartEventNametype源码

type KumoChartEventName = keyof KumoChartEventMap

The name of an event of the chart or of one of its modules.

Variables

KumoChartvariable源码

const KumoChart: React.ForwardRefExoticComponent<KumoChartProps & React.RefAttributes<ChartBase<unknown, unknown, unknown> | null>>

React component around createChart(). modules are read when the chart is created. Props replace the chart's data, orders, markers or alerts whenever a new value is passed (compare by reference, as React state does); every event of the chart and its modules is available as an on* prop, plus onReady with the chart instance. A ref receives the chart instance. Stream real-time bars with chart.data.update().

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