Data management
Line, scatter, and line-scatter series use datasets containing named numeric columns. Series select columns for their X and Y values, and multiple series can use the same dataset.
Dataset and column IDs connect the dataset definition, series bindings, and supplied data. Use matching IDs across these operations.
Scrolling heatmaps receive matrix samples directly. Each sample contains the intensity values for one column or row.
Adding datasets
A dataset requires an ID and column definitions. Its maximum sample count is optional.
Dataset IDs must be unique within their owning context. Multiple series can use the same dataset. See Sharing datasets for the sharing options supported by each client.
At chart creation
Include datasets in the chart configuration. Series in that configuration can reference them immediately.
The following creates a dataset containing time, three temperature measurements, and humidity:
- Blazor
- MAUI
- Uno
- Flutter
_chart = await _context.CreateChartAsync(new XYChartConfig
{
ContainerId = "signal-chart",
DataSets =
[
new DataSetConfig
{
Id = "measurements",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "time" },
new DataSetColumnConfig { Id = "temperature-1" },
new DataSetColumnConfig { Id = "temperature-2" },
new DataSetColumnConfig { Id = "temperature-3" },
new DataSetColumnConfig { Id = "humidity" },
],
},
],
});
_chart = await _context.CreateChartAsync(new XYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "measurements",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "time" },
new DataSetColumnConfig { Id = "temperature-1" },
new DataSetColumnConfig { Id = "temperature-2" },
new DataSetColumnConfig { Id = "temperature-3" },
new DataSetColumnConfig { Id = "humidity" },
],
},
],
});
_chart = await _context.CreateChartAsync(new XYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "measurements",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "time" },
new DataSetColumnConfig { Id = "temperature-1" },
new DataSetColumnConfig { Id = "temperature-2" },
new DataSetColumnConfig { Id = "temperature-3" },
new DataSetColumnConfig { Id = "humidity" },
],
},
],
});
LightningChart.xy(
license: license,
dataSets: const [
DataSetConfig(
id: 'measurements',
maxSampleCount: 1_000_000,
columns: [
DataSetColumnConfig(id: 'time'),
DataSetColumnConfig(id: 'temperature-1'),
DataSetColumnConfig(id: 'temperature-2'),
DataSetColumnConfig(id: 'temperature-3'),
DataSetColumnConfig(id: 'humidity'),
],
),
],
onChartCreated: (chart) {
_chart = chart;
},
);
To display the data, add series that reference the dataset and its columns.
After chart creation
Include a dataset creation configuration with a new unique ID in a chart update.
The following adds a new dataset while retaining the existing datasets:
- Blazor
- MAUI
- Uno
- Flutter
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "another-dataset",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "another-dataset",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "another-dataset",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
],
});
The following examples use the local chart controller obtained as shown in Updating a chart.
chart.update(
const UpdateXYChartConfig(
dataSets: [
DataSetConfig(
id: 'another-dataset',
maxSampleCount: 1_000_000,
columns: [
DataSetColumnConfig(id: 'x'),
DataSetColumnConfig(id: 'y'),
],
),
],
),
);
A series can reference the new dataset in the same chart update. Omitted datasets remain available. An empty dataset list does not remove anything.
Column patterns
For ordered data, declare a pattern separately for each column:
- Progressive indicates increasing values.
- Regressive indicates decreasing values.
- Leave the pattern unspecified for unordered values.
For example, configure a column containing increasing values as follows:
- Blazor
- MAUI
- Uno
- Flutter
new DataSetColumnConfig
{
Id = "time",
DataPattern = DataPattern.Progressive,
}
new DataSetColumnConfig
{
Id = "time",
DataPattern = DataPattern.Progressive,
}
new DataSetColumnConfig
{
Id = "time",
DataPattern = DataPattern.Progressive,
}
const DataSetColumnConfig(
id: 'time',
dataPattern: DataPattern.progressive,
)
Column definitions cannot be edited after dataset creation. To use a different set of columns, create a new dataset and update the relevant series bindings.
Loading data
Replace a dataset's samples when loading a historical recording or a new selection of data.
Supply an array for every configured column. Corresponding array indices represent the same sample.
The following loads the dataset created above. Obtain the arrays from your application's file, service, or API workflow.
- Blazor
- MAUI
- Uno
- Flutter
Here, xValues and yValues1 through yValues4 are double[] arrays:
_chart.SetData(new SetDataOptions
{
DataSetId = "measurements",
Columns = new Dictionary<string, double[]>
{
["time"] = xValues,
["temperature-1"] = yValues1,
["temperature-2"] = yValues2,
["temperature-3"] = yValues3,
["humidity"] = yValues4,
},
});
Here, xValues and yValues1 through yValues4 are double[] arrays:
_chart.SetData(new SetDataOptions
{
DataSetId = "measurements",
Columns = new Dictionary<string, double[]>
{
["time"] = xValues,
["temperature-1"] = yValues1,
["temperature-2"] = yValues2,
["temperature-3"] = yValues3,
["humidity"] = yValues4,
},
});
Here, xValues and yValues1 through yValues4 are double[] arrays:
_chart.SetData(new SetDataOptions
{
DataSetId = "measurements",
Columns = new Dictionary<string, double[]>
{
["time"] = xValues,
["temperature-1"] = yValues1,
["temperature-2"] = yValues2,
["temperature-3"] = yValues3,
["humidity"] = yValues4,
},
});
Here, xValues and yValues1 through yValues4 are Float64List instances from dart:typed_data:
chart.setData(
SetDataOptions(
dataSetId: 'measurements',
columns: {
'time': xValues,
'temperature-1': yValues1,
'temperature-2': yValues2,
'temperature-3': yValues3,
'humidity': yValues4,
},
),
);
Historical data available before widget creation can also be supplied through initialData:
LightningChart.xy(
license: license,
dataSets: const [
DataSetConfig(
id: 'measurements',
maxSampleCount: 1_000_000,
columns: [
DataSetColumnConfig(id: 'time'),
DataSetColumnConfig(id: 'temperature-1'),
DataSetColumnConfig(id: 'temperature-2'),
DataSetColumnConfig(id: 'temperature-3'),
DataSetColumnConfig(id: 'humidity'),
],
),
],
initialData: [
SetDataOptions(
dataSetId: 'measurements',
columns: {
'time': xValues,
'temperature-1': yValues1,
'temperature-2': yValues2,
'temperature-3': yValues3,
'humidity': yValues4,
},
),
],
onChartCreated: (chart) {
_chart = chart;
},
);
All series bound to the dataset display the replaced samples. Their configurations remain unchanged.
Appending data
Append incoming batches to retain existing samples and add new ones. Supply every configured column in each batch.
Historical loading and streaming use the same dataset definition. A chart can load a recording and continue with incoming samples.
- Blazor
- MAUI
- Uno
- Flutter
Call this for each received batch. Here, batchX and batchY1 through batchY4 are double[] arrays:
_chart.AppendData(new AppendDataOptions
{
DataSetId = "measurements",
Columns = new Dictionary<string, double[]>
{
["time"] = batchX,
["temperature-1"] = batchY1,
["temperature-2"] = batchY2,
["temperature-3"] = batchY3,
["humidity"] = batchY4,
},
});
Call this for each received batch. Here, batchX and batchY1 through batchY4 are double[] arrays:
_chart.AppendData(new AppendDataOptions
{
DataSetId = "measurements",
Columns = new Dictionary<string, double[]>
{
["time"] = batchX,
["temperature-1"] = batchY1,
["temperature-2"] = batchY2,
["temperature-3"] = batchY3,
["humidity"] = batchY4,
},
});
Call this for each received batch. Here, batchX and batchY1 through batchY4 are double[] arrays:
_chart.AppendData(new AppendDataOptions
{
DataSetId = "measurements",
Columns = new Dictionary<string, double[]>
{
["time"] = batchX,
["temperature-1"] = batchY1,
["temperature-2"] = batchY2,
["temperature-3"] = batchY3,
["humidity"] = batchY4,
},
});
Call this through the controller for each received batch. Here, batchX and batchY1 through batchY4 are Float64List instances:
chart.appendData(
AppendDataOptions(
dataSetId: 'measurements',
columns: {
'time': batchX,
'temperature-1': batchY1,
'temperature-2': batchY2,
'temperature-3': batchY3,
'humidity': batchY4,
},
),
);
Appending samples does not require another series configuration update. To make axes follow incoming data, see Scrolling and fitting.
Data cleaning / maximum memory use
Set a maximum sample count for every dataset. It defines the retained data window: when an appended batch would exceed the limit, the oldest samples are removed first (FIFO). This gives streaming applications predictable memory use while retaining the newest data.
The maximum can be increased during the dataset lifetime, but it cannot be reduced. If omitted, the default value is 2,000,000 samples.
- Blazor
- MAUI
- Uno
- Flutter
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new UpdateDataSetConfig
{
Id = "measurements",
MaxSampleCount = 1_500_000,
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new UpdateDataSetConfig
{
Id = "measurements",
MaxSampleCount = 1_500_000,
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new UpdateDataSetConfig
{
Id = "measurements",
MaxSampleCount = 1_500_000,
},
],
});
chart.update(
const UpdateXYChartConfig(
dataSets: [
UpdateDataSetConfig(
id: 'measurements',
maxSampleCount: 1_500_000,
),
],
),
);
Clearing data
Clear a dataset to remove its samples while retaining its column definitions and series bindings.
- Blazor
- MAUI
- Uno
- Flutter
_chart.ClearData(new ClearDataOptions
{
DataSetId = "measurements",
});
_chart.ClearData(new ClearDataOptions
{
DataSetId = "measurements",
});
_chart.ClearData(new ClearDataOptions
{
DataSetId = "measurements",
});
chart.clearData(
const ClearDataOptions(
dataSetId: 'measurements',
),
);
Removing datasets
Remove a dataset by its ID. Removal is rejected while any series in the owning context still uses the dataset. Rebind or remove those series first, or include their binding updates or removal requests in the same chart update.
- Blazor
- MAUI
- Uno
- Flutter
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new UpdateDataSetConfig
{
Id = "another-dataset",
Remove = true,
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new UpdateDataSetConfig
{
Id = "another-dataset",
Remove = true,
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new UpdateDataSetConfig
{
Id = "another-dataset",
Remove = true,
},
],
});
chart.update(
const UpdateXYChartConfig(
dataSets: [
UpdateDataSetConfig(
id: 'another-dataset',
remove: true,
),
],
),
);
Replacing a dataset
One chart update can create a replacement dataset, reconnect an existing series, and remove the old dataset.
In the following example, the existing another-dataset is used only by the line-series being updated. Its new replacement-dataset has the same column IDs, so the existing X/Y bindings can be retained.
- Blazor
- MAUI
- Uno
- Flutter
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "replacement-dataset",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
new UpdateDataSetConfig
{
Id = "another-dataset",
Remove = true,
},
],
Series =
[
new UpdateLineSeriesConfig
{
Id = "line-series",
DataSetId = "replacement-dataset",
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "replacement-dataset",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
new UpdateDataSetConfig
{
Id = "another-dataset",
Remove = true,
},
],
Series =
[
new UpdateLineSeriesConfig
{
Id = "line-series",
DataSetId = "replacement-dataset",
},
],
});
_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "replacement-dataset",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
new UpdateDataSetConfig
{
Id = "another-dataset",
Remove = true,
},
],
Series =
[
new UpdateLineSeriesConfig
{
Id = "line-series",
DataSetId = "replacement-dataset",
},
],
});
chart.update(
const UpdateXYChartConfig(
dataSets: [
DataSetConfig(
id: 'replacement-dataset',
maxSampleCount: 1_000_000,
columns: [
DataSetColumnConfig(id: 'x'),
DataSetColumnConfig(id: 'y'),
],
),
UpdateDataSetConfig(
id: 'another-dataset',
remove: true,
),
],
series: [
UpdateLineSeriesConfig(
id: 'line-series',
dataSetId: 'replacement-dataset',
),
],
),
);
The replacement starts without samples. Load or append data to its ID to display it.
Sharing datasets
Series can share a dataset while selecting different columns or axes. Data operations affect the dataset, so every series bound to it sees the changes.
Where charts share a context, supply data once through that context rather than sending a separate copy for each chart. See LCLA Context for context ownership and sharing.
- Blazor
- MAUI
- Uno
- Flutter
Datasets can also be created directly through the shared context:
_context.ConfigureDataSets(
[
new DataSetConfig
{
Id = "shared-dataset",
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
]);
Charts created through that context can reference this dataset. The method also accepts UpdateDataSetConfig to increase data retention or remove an unused dataset.
Data can be supplied through _context.SetData(), _context.AppendData(), and _context.ClearData() using the same options as the chart methods.
Datasets can also be created directly through the shared context:
_context.ConfigureDataSets(
[
new DataSetConfig
{
Id = "shared-dataset",
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
]);
Charts must belong to the same context to share this dataset. Separate WebViews with separate contexts have independent datasets.
Data can be supplied through _context.SetData(), _context.AppendData(), and _context.ClearData() using the same options as the chart methods.
Datasets can also be created directly through the shared context:
_context.ConfigureDataSets(
[
new DataSetConfig
{
Id = "shared-dataset",
Columns =
[
new DataSetColumnConfig { Id = "x" },
new DataSetColumnConfig { Id = "y" },
],
},
]);
Charts must belong to the same context to share this dataset. Separate WebViews with separate contexts have independent datasets.
Data can be supplied through _context.SetData(), _context.AppendData(), and _context.ClearData() using the same options as the chart methods.
In Flutter, each chart owns its datasets. Series within the same chart can share a dataset.
Create and update datasets through the stored _chart controller's update() method. Supply samples through its setData(), appendData(), and clearData() methods.
Matrix data
Supply matrix data directly to a heatmap using its series ID. A scrolling heatmap receives samples containing intensity values. Each sample becomes a column or row, according to the series's scrolling dimension.
Every sample must contain the number of values specified by the series resolution.
Appending samples
The following supplies samples to a scrolling heatmap with the ID "heatmap".
- Blazor
- MAUI
- Uno
- Flutter
Here, samples is an IReadOnlyList<float[]> containing the received samples:
_chart.AppendMatrixData(new AppendMatrixDataOptions
{
SeriesId = "heatmap",
Samples = samples,
});
Here, samples is an IReadOnlyList<float[]> containing the received samples:
_chart.AppendMatrixData(new AppendMatrixDataOptions
{
SeriesId = "heatmap",
Samples = samples,
});
Here, samples is an IReadOnlyList<float[]> containing the received samples:
_chart.AppendMatrixData(new AppendMatrixDataOptions
{
SeriesId = "heatmap",
Samples = samples,
});
Here, samples is a List<Float32List>. Import dart:typed_data to use Float32List.
chart.appendMatrixData(
AppendMatrixDataOptions(
seriesId: 'heatmap',
samples: samples,
),
);
Without a starting sample index, samples are appended after the existing data. The same operation can supply a historical recording as a batch or append batches as they arrive.
Using timestamps
Incoming samples are not always evenly spaced in time. To display their timing correctly, configure the heatmap's step along the scrolling axis as the smallest time interval you need to represent.
Set the grid's start position to the first sample's timestamp. Each incoming timestamp then identifies a position relative to that starting time:
sample index = round((timestamp − first timestamp) / time step)
For example, with a 5 ms step, a sample acquired 10 ms after the first sample belongs at index 2.
The following example uses a heatmap scrolling by columns, configured with a 5 ms X step. Timestamps are Unix timestamps in milliseconds. Use a DateTime tick strategy on the X axis to display dates and times.
- Blazor
- MAUI
- Uno
- Flutter
Add the field and method to the component. Call HandleIncomingSample() with each sample's acquisition timestamp and intensity values after chart creation:
private long? _firstTimestampMs;
private void HandleIncomingSample(long timestampMs, float[] sample)
{
if (_chart is null) return;
const double stepMs = 5;
if (_firstTimestampMs is null)
{
_firstTimestampMs = timestampMs;
_chart.Update(new UpdateXYChartConfig
{
Series =
[
new UpdateScrollingHeatmapSeriesConfig
{
Id = "heatmap",
Start = new PointConfig { X = timestampMs, Y = 0 },
},
],
});
}
var iSample = (int)Math.Round(
(timestampMs - _firstTimestampMs.Value) / stepMs,
MidpointRounding.AwayFromZero);
_chart.AppendMatrixData(new AppendMatrixDataOptions
{
SeriesId = "heatmap",
ISample = iSample,
Samples = [sample],
});
}
Add the field and method to the page. Call HandleIncomingSample() with each sample's acquisition timestamp and intensity values after chart creation:
private long? _firstTimestampMs;
private void HandleIncomingSample(long timestampMs, float[] sample)
{
if (_chart is null) return;
const double stepMs = 5;
if (_firstTimestampMs is null)
{
_firstTimestampMs = timestampMs;
_chart.Update(new UpdateXYChartConfig
{
Series =
[
new UpdateScrollingHeatmapSeriesConfig
{
Id = "heatmap",
Start = new PointConfig { X = timestampMs, Y = 0 },
},
],
});
}
var iSample = (int)Math.Round(
(timestampMs - _firstTimestampMs.Value) / stepMs,
MidpointRounding.AwayFromZero);
_chart.AppendMatrixData(new AppendMatrixDataOptions
{
SeriesId = "heatmap",
ISample = iSample,
Samples = [sample],
});
}
Add the field and method to the page. Call HandleIncomingSample() with each sample's acquisition timestamp and intensity values after chart creation:
private long? _firstTimestampMs;
private void HandleIncomingSample(long timestampMs, float[] sample)
{
if (_chart is null) return;
const double stepMs = 5;
if (_firstTimestampMs is null)
{
_firstTimestampMs = timestampMs;
_chart.Update(new UpdateXYChartConfig
{
Series =
[
new UpdateScrollingHeatmapSeriesConfig
{
Id = "heatmap",
Start = new PointConfig { X = timestampMs, Y = 0 },
},
],
});
}
var iSample = (int)Math.Round(
(timestampMs - _firstTimestampMs.Value) / stepMs,
MidpointRounding.AwayFromZero);
_chart.AppendMatrixData(new AppendMatrixDataOptions
{
SeriesId = "heatmap",
ISample = iSample,
Samples = [sample],
});
}
Add the field and method to _SignalChartState. Call _handleIncomingSample() with each sample's acquisition timestamp and intensity values after chart creation:
int? _firstTimestampMs;
void _handleIncomingSample(int timestampMs, Float32List sample) {
final chart = _chart;
if (chart == null) return;
const stepMs = 5.0;
if (_firstTimestampMs == null) {
_firstTimestampMs = timestampMs;
chart.update(UpdateXYChartConfig(
series: [
UpdateScrollingHeatmapSeriesConfig(
id: 'heatmap',
start: PointConfig(x: timestampMs.toDouble(), y: 0),
),
],
));
}
final iSample =
((timestampMs - _firstTimestampMs!) / stepMs).round();
chart.appendMatrixData(AppendMatrixDataOptions(
seriesId: 'heatmap',
iSample: iSample,
samples: [sample],
));
}
Supplying a sample index places the values at that grid position. Gaps between samples are filled by repeating the preceding sample.
For a heatmap scrolling by rows, use the Y coordinate for the start position and time step.
When sending multiple samples in one call, they occupy consecutive indices. Send samples separately when their timestamps require different spacing.
Clearing matrix data
Clear a heatmap's data using its series ID. The series and its configuration, including the palette, grid start, and step, remain unchanged.
- Blazor
- MAUI
- Uno
- Flutter
_chart.ClearMatrixData(new ClearMatrixDataOptions
{
SeriesId = "heatmap",
});
_chart.ClearMatrixData(new ClearMatrixDataOptions
{
SeriesId = "heatmap",
});
_chart.ClearMatrixData(new ClearMatrixDataOptions
{
SeriesId = "heatmap",
});
chart.clearMatrixData(
const ClearMatrixDataOptions(
seriesId: 'heatmap',
),
);
New samples can be supplied to the same series after clearing. Clearing does not stop an active data stream.