Skip to content

DataMapping

Defined in: types/index.ts:149

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

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

datasets?

optional datasets?: Dataset[]

Defined in: types/index.ts:165

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


groupField?

optional groupField?: string

Defined in: types/index.ts:169

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


labelField?

optional labelField?: string

Defined in: types/index.ts:153

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


labels?

optional labels?: string[]

Defined in: types/index.ts:161

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


seriesNames?

optional seriesNames?: string[]

Defined in: types/index.ts:159

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


sizeField?

optional sizeField?: string

Defined in: types/index.ts:167

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


valueField?

optional valueField?: string

Defined in: types/index.ts:157

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


values?

optional values?: number[]

Defined in: types/index.ts:163

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


x?

optional x?: string

Defined in: types/index.ts:151

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


y?

optional y?: string | string[]

Defined in: types/index.ts:155

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