Skip to main content

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:

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

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:

_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new DataSetConfig
{
Id = "another-dataset",
MaxSampleCount = 1_000_000,
Columns =
[
new DataSetColumnConfig { Id = "x" },
new 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:

new 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.

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

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.

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

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.

_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new UpdateDataSetConfig
{
Id = "measurements",
MaxSampleCount = 1_500_000,
},
],
});

Clearing data​

Clear a dataset to remove its samples while retaining its column definitions and series bindings.

_chart.ClearData(new 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.

_chart.Update(new UpdateXYChartConfig
{
DataSets =
[
new 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.

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

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.

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.

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".

Here, samples is an IReadOnlyList<float[]> containing the received samples:

_chart.AppendMatrixData(new 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.

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

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.

_chart.ClearMatrixData(new ClearMatrixDataOptions
{
SeriesId = "heatmap",
});

New samples can be supplied to the same series after clearing. Clearing does not stop an active data stream.