Skip to content

BaseChart

Defined in: core/base.ts:49

Shared lifecycle, layout, theming, accessibility, and event plumbing for every SwiftChart chart class. End users typically don’t construct BaseChart directly — they instantiate one of the concrete subclasses (LineChart, BarChart, PieChart, …) — but BaseChart is the type surfaced from chartRef.current.chart and from the imperative API, so the public methods documented here apply to every chart.

Public surface used by consumers:

  • setData — replace the chart’s data
  • update — patch config or data without recreating the chart
  • setTheme — switch palette by registered name
  • resize — force a re-layout
  • toDataURL — export as PNG (or other canvas-supported format)
  • destroy — tear down listeners, observers, tooltip, canvas

Internals worth knowing about (protected):

  • _rebakeColorsForTheme() — re-resolves colorField colours when the theme changes. Pie/Funnel/Treemap override it to redo their bake.

BaseChartConfig for the cross-chart config shape.

new BaseChart(container, config?): BaseChart

Defined in: core/base.ts:122

string | HTMLElement

BaseChartConfig = {}

BaseChart

animator: Animator

Defined in: core/base.ts:63


animProgress: number = 1

Defined in: core/base.ts:74


canvas: HTMLCanvasElement

Defined in: core/base.ts:60


config: Required<Pick<BaseChartConfig, "title" | "animate" | "animDuration" | "animEasing" | "responsive" | "showGrid" | "showTooltip" | "showLegend" | "legendPosition" | "subtitle">> & BaseChartConfig

Defined in: core/base.ts:52


container: HTMLElement

Defined in: core/base.ts:51

Host element the canvas was mounted into.


ctx: CanvasRenderingContext2D

Defined in: core/base.ts:61


height: number = 0

Defined in: core/base.ts:89


hoverIndex: number = -1

Defined in: core/base.ts:65


hoverSeriesIndex: number = -1

Defined in: core/base.ts:73

Index of the series under the cursor, or -1 when the hover is not series-specific (e.g. a column hit on a multi-series line chart). Charts that can pinpoint a series — bubble, scatter, network, sankey, marimekko, treemap — set this in their _onMouse. Single-series charts report 0 automatically via _buildClickEvent.


padding: Padding

Defined in: core/base.ts:90


resolved: ResolvedData

Defined in: core/base.ts:75


theme: Theme

Defined in: core/base.ts:62


tooltip: Tooltip | null

Defined in: core/base.ts:64


width: number = 0

Defined in: core/base.ts:88

get plotArea(): PlotArea

Defined in: core/base.ts:328

PlotArea

abstract _draw(): void

Defined in: core/base.ts:951

void


abstract _onMouse(e): void

Defined in: core/base.ts:950

MouseEvent

void


destroy(): void

Defined in: core/base.ts:461

void


resize(): void

Defined in: core/base.ts:432

void


setData(data, mapping?): void

Defined in: core/base.ts:350

Record<string, any>[] | null | undefined

DataMapping

void


setTheme(theme): void

Defined in: core/base.ts:389

Switch theme. Accepts a registered theme name ('midnight', 'arctic', 'ember', 'forest', or any name passed to addTheme) or a full Theme object — same surface that the constructor accepts via config.theme.

Theme | ThemeName

void


toDataURL(type?, quality?, options?): string

Defined in: core/base.ts:446

Export the current chart as a data URL.

canvas.toDataURL() always returns the backing-store bitmap, which is DPR-multiplied — a 400×300 chart on a DPR=2 display exports as 800×600. Pass { scale: 'css' } to downscale the export to on-screen CSS dimensions (typical for “Save as PNG” buttons); the default 'native' keeps the full backing-store resolution.

string = 'image/png'

number = 0.92

"native" | "css"

string


update(arg, mapping?): void

Defined in: core/base.ts:401

Polymorphic update:

  • update(dataArray, mapping?) — replaces data (alias of setData).
  • update(configPatch) — patches non-data config (theme, title, padding, etc.).

Record<string, any>[] | Partial<BaseChartConfig>

DataMapping

void