Skip to content

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.

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] }],
});

optional colorField?: 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.

chart.setData(rows, { x: 'name', y: 'count', colorField: 'status' });

optional colorMap?: Record<string, string>

Defined in: types/index.ts:298

Optional category → colour lookup used together with colorField for categorical data-binding.

chart.setData(rows, {
x: 'name', y: 'count', colorField: 'status',
colorMap: { ok: '#22c55e', warn: '#f59e0b', err: '#ef4444' },
});

optional datasets?: Dataset[]

Defined in: types/index.ts:270

Pre-built datasets - Chart.js-style escape hatch.


optional groupField?: string

Defined in: types/index.ts:274

Scatter-only: field whose value groups points (drives colour assignment).


optional labelField?: string

Defined in: types/index.ts:258

Alias for x used by pie/donut/treemap to read the slice label.


optional labels?: string[]

Defined in: types/index.ts:266

Pre-built labels - used when bypassing field-mapping.


optional seriesNames?: string[]

Defined in: types/index.ts:264

Override the auto-derived series labels (one per y field).


optional sizeField?: string

Defined in: types/index.ts:272

Scatter-only: field whose value sets each point’s radius.


optional valueField?: string

Defined in: types/index.ts:262

Alias for y used by pie/donut/treemap to read the slice value.


optional values?: number[]

Defined in: types/index.ts:268

Pre-built numeric values - used by pie/donut when bypassing field-mapping.


optional x?: string

Defined in: types/index.ts:256

Field whose value becomes the X-axis label (categorical) for line/bar/area/radar/stacked.


optional y?: string | string[]

Defined in: types/index.ts:260

Single field name or array of field names to plot as Y-axis series.