Skip to content

ChartRef

Defined in: react/index.tsx:76

Imperative handle exposed by every SwiftChart React component via forwardRef. Use it to reach the underlying chart instance, force a resize, or export a PNG snapshot — without leaking renderer details into your component tree.

import { useRef } from 'react';
import { Line, type ChartRef } from '@arshad-shah/swift-chart/react';
const ref = useRef<ChartRef>(null);
<Line ref={ref} data={...} mapping={{ x: 'month', y: 'revenue' }} />
<button onClick={() => download(ref.current?.toDataURL())}>Save PNG</button>

BaseChart for the full surface available via chart.

chart: BaseChart | null

Defined in: react/index.tsx:83

The underlying SwiftChart instance, or null while the host element is unmounted (between render and the first effect, or after destroy). Use it for imperative operations not exposed as props (e.g. chart.update({ animDuration: 0 })).


resize: () => void

Defined in: react/index.tsx:88

Force a resize + re-layout. Useful after a parent’s CSS changes shape outside a ResizeObserver-tracked dimension.

void


toDataURL: (type?, quality?, options?) => string | null

Defined in: react/index.tsx:96

Export the current canvas as a data URL. Defaults to PNG; pass 'image/jpeg' or 'image/webp' (with quality 0–1) for those formats. Pass { scale: 'css' } to export at on-screen CSS-pixel resolution instead of the DPR-multiplied backing store (useful for “Save as PNG” buttons). Returns null if the chart isn’t mounted.

string

number

"native" | "css"

string | null