DataMapping
Defined in: types/index.ts:254
Tells SwiftChart how to read your data.
SwiftChart accepts any object array. Use DataMapping to pick which
field is the X axis and which is the Y axis, or to pass pre-built
{ labels, datasets } directly.
Examples
Section titled “Examples”chart.setData([ { month: 'Jan', sales: 420, cost: 280 }, { month: 'Feb', sales: 510, cost: 320 },]);// First string field becomes labels, all numeric fields become series.chart.setData(rows, { x: 'timestamp', y: ['cpu', 'memory'], seriesNames: ['CPU %', 'Memory %'],});chart.setData(rows, { labelField: 'source', valueField: 'visits' });chart.setData([], { labels: ['Q1', 'Q2', 'Q3'], datasets: [{ label: 'Revenue', data: [100, 200, 350] }],});Properties
Section titled “Properties”colorField?
Section titled “colorField?”
optionalcolorField?:string
Defined in: types/index.ts:285
Field whose value sets each datum’s colour. The value may be either a CSS
colour string (used as-is) or a category key resolved via colorMap, or
— when no map is given — hashed deterministically into the theme palette.
Example
Section titled “Example”chart.setData(rows, { x: 'name', y: 'count', colorField: 'status' });colorMap?
Section titled “colorMap?”
optionalcolorMap?:Record<string,string>
Defined in: types/index.ts:298
Optional category → colour lookup used together with colorField for
categorical data-binding.
Example
Section titled “Example”chart.setData(rows, { x: 'name', y: 'count', colorField: 'status', colorMap: { ok: '#22c55e', warn: '#f59e0b', err: '#ef4444' },});datasets?
Section titled “datasets?”
optionaldatasets?:Dataset[]
Defined in: types/index.ts:270
Pre-built datasets - Chart.js-style escape hatch.
groupField?
Section titled “groupField?”
optionalgroupField?:string
Defined in: types/index.ts:274
Scatter-only: field whose value groups points (drives colour assignment).
labelField?
Section titled “labelField?”
optionallabelField?:string
Defined in: types/index.ts:258
Alias for x used by pie/donut/treemap to read the slice label.
labels?
Section titled “labels?”
optionallabels?:string[]
Defined in: types/index.ts:266
Pre-built labels - used when bypassing field-mapping.
seriesNames?
Section titled “seriesNames?”
optionalseriesNames?:string[]
Defined in: types/index.ts:264
Override the auto-derived series labels (one per y field).
sizeField?
Section titled “sizeField?”
optionalsizeField?:string
Defined in: types/index.ts:272
Scatter-only: field whose value sets each point’s radius.
valueField?
Section titled “valueField?”
optionalvalueField?:string
Defined in: types/index.ts:262
Alias for y used by pie/donut/treemap to read the slice value.
values?
Section titled “values?”
optionalvalues?:number[]
Defined in: types/index.ts:268
Pre-built numeric values - used by pie/donut when bypassing field-mapping.
optionalx?:string
Defined in: types/index.ts:256
Field whose value becomes the X-axis label (categorical) for line/bar/area/radar/stacked.
optionaly?:string|string[]
Defined in: types/index.ts:260
Single field name or array of field names to plot as Y-axis series.