WPF Charting Documentation - SciChart WPF Charts SDK v5.x
Manipulating DataSeries Data

The following sections show how you can manipulate data in the DataSeries types in SciChart.

Append, Update, Insert, Remove

All DataSeries types include Append, Update, Insert, Remove methods. Many of these also have overloads which accept a range of data:

e.g. the XyDataSeries<TX,TY> interface is declared as follows:

Append, Update, Insert, Remove
Copy Code
/// <summary>
/// Defines the interface to a typed Xy DataSeries, which contains columns of X-Values and Y-Values.
/// </summary>   
public interface IXyDataSeries<TX, TY> : IDataSeries<TX ,TY>, IXyDataSeries
       where TX:IComparable
       where TY:IComparable
{
       /// <summary>
       /// Appends an X, Y point to the series.
       /// </summary>
       /// <param name="x">The X Value.</param>
       /// <param name="y">The Y Value.</param>
       void Append(TX x, TY y);

       /// <summary>
       /// Appends an X, Y point to the series.
       /// </summary>
       /// <param name="x">The X Value.</param>
       /// <param name="y">The Y Value.</param>
       /// <param name="metadata">The metadata.</param>
       void Append(TX x, TY y, IPointMetadata metadata);

       /// <summary>
       /// Appends a list of X, Y points to the series.
       /// </summary>
       /// <exception cref="InvalidOperationException">Exception will be thrown
        /// if the count of x and y differ.</exception>
       /// <param name="x">The list of X points.</param>
       /// <param name="y">The list of Y points.</param>
       void Append(IEnumerable<TX> x, IEnumerable<TY> y);

       /// <summary>
       /// Appends a list of X, Y points to the series.
       /// </summary>
       /// <exception cref="InvalidOperationException">Exception will be thrown
       /// if the count of x and y differ.</exception>
       /// <param name="x">The list of X points.</param>
       /// <param name="y">The list of Y points.</param>
       /// <param name="metadata">The list of points' metadata.</param>
       void Append(IEnumerable<TX> x, IEnumerable<TY> y,
                           IEnumerable<IPointMetadata> metadata);

       /// <summary>
       /// Updates an X,Y point specified by the X-Value passed in.
       /// </summary>
       /// <param name="index">The index to update at.</param>
       /// <param name="y">The new Y value.</param>
       /// <exception cref="InvalidOperationException">Thrown if the x value is not
       /// in the DataSeries.</exception>
       void Update(int index, TY y);

       /// <summary>
       /// Updates an X,Y point specified by the index passed in.
       /// </summary>
       /// <param name="index">The index to update at.</param>
       /// <param name="y">The new Y value.</param>
       /// <param name="metadata">The new metadata object.</param>
       /// <exception cref="InvalidOperationException">Thrown if the x value is not
       /// in the DataSeries.</exception>
       void Update(int index, TY y, IPointMetadata metadata);

       /// <summary>
       /// Inserts an X,Y point at the specified index.
       /// </summary>
       /// <param name="index">The index to insert at.</param>
       /// <param name="x">The X value.</param>
       /// <param name="y">The Y value.</param>
       void Insert(int index, TX x, TY y);

       /// <summary>
       /// Inserts an X,Y point at the specified index.
       /// </summary>
       /// <param name="index">The index to insert at.</param>
       /// <param name="x">The X value.</param>
       /// <param name="y">The Y value.</param>
       /// <param name="metadata">The metadata.</param>
       void Insert(int index, TX x, TY y, IPointMetadata metadata);

       /// <summary>
       /// Inserts a list of X, Y points at the specified index.
       /// </summary>
       /// <exception cref="InvalidOperationException">Exception will be thrown if
       /// the count of x and y differ.</exception>
       /// <param name="startIndex">The index to insert at.</param>
       /// <param name="x">The list of X points.</param>
       /// <param name="y">The list of Y points.</param>
       void InsertRange(int startIndex, IEnumerable<TX> x, IEnumerable<TY> y);

       /// <summary>
       /// Inserts a list of X, Y points at the specified index.
       /// </summary>
       /// <exception cref="InvalidOperationException">Exception will be thrown if
       /// the count of x and y differ.</exception>
       /// <param name="startIndex">The index to insert at.</param>
       /// <param name="x">The list of X points.</param>
       /// <param name="y">The list of Y points.</param>
       /// <param name="metadata">The list of points' metadata.</param>
       void InsertRange(int startIndex, IEnumerable<TX> x, IEnumerable<TY> y,
                           IEnumerable<IPointMetadata> metadata);

        /// <summary>
        /// Removes a point at the specified index.
        /// </summary>
        /// <param name="index"></param>
        void RemoveAt(int index);

        /// <summary>
        /// Removes a range of points starting from the specified index.
        /// </summary>
        /// <param name="startIndex">Starting index of the range of elements
        /// to remove.</param>
        /// <param name="count">The number of elements to remove.</param>
        void RemoveRange(int startIndex, int count);      
        /// <summary>
        /// Clears the series, resetting internal lists to zero size.
        /// </summary>
        void Clear();
}

Accessing X,Y Values (read-only)

All DataSeries types expose the lists of underlying data. These should be treated as read-only. Data can be accessed by casting to the underlying list type.

e.g.

Accessing X,Y Values
Copy Code
// Accessing the Data-values of an XyDataSeries
var xyDataSeries = new XyDataSeries<DateTime, double>();
xyDataSeries.Append(...);

var xDataReadOnly = (IList<DateTime>)xyDataSeries.XValues;
var yDataReadOnly = (IList<double>)xyDataSeries.XValues;

// Accessing the Data-Values of an OhlcDataSeries
var ohlcDataSeries = new OhlcDataSeries<DateTime, double>();
ohlcDataSeries.Append(...);

var timeDataReadOnly = (IList<DateTime>)ohlcDataSeries.XValues;
var openDataReadOnly = (IList<DateTime>)ohlcDataSeries.OpenValues;
var highDataReadOnly = (IList<double>)ohlcDataSeries.HighValues;
var lowDataReadOnly = (IList<double>)ohlcDataSeries.LowValues;
var closeDataReadOnly = (IList<double>)ohlcDataSeries.CloseValues;

XRange and YRange

All DataSeries types expose the XRange and YRange of the underlying DataSeries.

NOTE: These perform a calculation every time the property is accessed, so should be used sparingly.

XRange and YRange
Copy Code
var xyDataSeries = new XyDataSeries<double, double>();
xyDataSeries.Append(...);

DoubleRange xRange = xyDataSeries.XRange.AsDoubleRange();
DoubleRange yRange = xyDataSeries.YRange.AsDoubleRange();

Fifo (First-In-First-Out) DataSeries

DataSeries allow First-In-First-Out behaviour, where a maximum capacity is set, once reached, old data-points are discarded.

To declare a Fifo dataseries, simply set the FifoCapacity property.

Fifo (First-In-First-Out) DataSeries
Copy Code
var xyDataSeries = new XyDataSeries<double, double>() { FifoCapacity = 1000 };

The behaviour will be, once 1001 points have been added, the first point will be discarded. Appending another 5 points, the next, oldest 5 points will be discarded. The window continues to scroll no matter how many points are appended and memory never increase beyond 1000 points.

Fifo DataSeries are a very memory and CPU efficient way of scrolling and discarding old data.

 

 


SCICHART ® is a Registered Trademark in the UK, US and EEC. Copyright SciChart Ltd 2011-2018.

Email us to give feedback!