Skip to main content
Version: 7.1.2

Editing existing data

The new XY features also introduce two methods for editing data that has been previously pushed in: alterSamples and alterSamplesByID.

alterSamples

This method allows you to specify a starting location in the existing data set with a sample index. This is a simple counter that points to the n:th sample that has been pushed to the data set, in the order of appearance.

PointLineAreaSeries.appendSamples({ yValues: [0, 1, 2, 3, 4, 5] })
PointLineAreaSeries.alterSamples(1, { yValues: [10, 11] })
// ---> Data set = [0, 10, 11, 3, 4, 5]

alterSamples lets you modify any sample values, X, Y, lookup value, color and ID. It also supports automatically appending data if you attempt to modify samples that would come after the existing ones.

alterSamplesByID

This method allows you to arbitrarily edit any number of existing samples by identifying them with an user supplied ID property:

PointLineAreaSeries.appendSamples({
yValues: [100, 101, 102, 103, 104],
ids: [0, 1, 2, 3, 4]
})
PointLineAreaSeries.alterSamplesByID(
[2, 4], // Edit samples ID:2 and ID:4
{
yValues: [200, 201]
}
)
// ---> Data set yValues = [100, 101, 200, 103, 201]

IMPORTANT, in order to use ID values, you have to enable them when creating the DataSetXY or Series:

const series = chart.addPointLineAreaSeries({ ids: true })
// or
const dataSet = new DataSetXY({ ids: true })