Pre loader

Updating X-Axis Values within XyDataSeries

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

Hello,

is there a way to update the X-Axis Values within an XYDataSeries?
What I found was the Update function to update the Y-Values.
https://www.scichart.com/documentation/win/current/webframe.html#SciChart.Charting~SciChart.Charting.Model.DataSeries.XyDataSeries%602~Update.html

But I can’t figure out how to update the X Values of the DataSeries.

The XyzDataSeries3D does support the functionality to update also the X Value.
https://www.scichart.com/documentation/win/current/webframe.html#SciChart.Charting3D~SciChart.Charting3D.Model.XyzDataSeries3D%603~Update.html

But for the NonUniformGridDataSeries3D I can’t figure out how to update any point.

Maybe I am missing something, just let me know.

Best Regards,
Nick

Version
6.0.2
  • You must to post comments
0
0

Hi Nick

the IXyDataSeries interface has the following API:

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

This is in addition to IDataSeries which has the following API

public interface IDataSeries<TX, TY> : IDataSeries
        where TX : IComparable
        where TY : IComparable
    {
        /// <summary>
        /// Gets the X Values of this series.
        /// </summary>
        new IList<TX> XValues { get; }

        /// <summary>
        /// Gets the Y Values of this series.
        /// </summary>
        new IList<TY> YValues { get; }             

        /// <summary>
        /// Appends an X, Y point to the series.
        /// </summary>
        /// <exception cref="InvalidOperationException">Exception will be thrown if the count of y differ.</exception>
        /// <param name="x">The X value.</param>
        /// <param name="yValues">The Y values (depends on series type).</param>
        void Append(TX x, params TY[] yValues);

        /// <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 each y differ.</exception>
        /// <param name="x">The list of X points.</param>
        /// <param name="yValues">Lists of Y points (depends on series type).</param>
        void Append(IEnumerable<TX> x, params IEnumerable<TY>[] yValues);

        /// <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>
        /// Creates a deep copy of a DataSeries.
        /// </summary>
        /// <returns></returns>
        IDataSeries<TX, TY> Clone();

        /// <summary>
        /// Used internally by AutoRanging algorithm. 
        /// When overriden in a derived class, gets the Min(existingYMin, currentMin), where currentMin is the minimum at the specified index.
        /// </summary>
        /// <param name="index">The index to the underlying dataset.</param>
        /// <param name="existingYMin">The existing minimum.</param>
        /// <returns>The new YMin, which is the Min(existingYMin, currentMin).</returns>
        TY GetYMinAt(int index, TY existingYMin);

        /// <summary>
        /// Used internally by AutoRanging algorithm. 
        /// When overriden in a derived class, gets the Max(existingYMax, currentMax), where currentMax is the maximum at the specified index.
        /// </summary>
        /// <param name="index">The index to the underlying dataset.</param>
        /// <param name="existingYMax">The existing maximum.</param>
        /// <returns>The new YMax, which is the Min(existingYMax, currentMax).</returns>
        TY GetYMaxAt(int index, TY existingYMax);
    }

So you can’t directly update an X value but you could do this

dataSeries.removeAt(index);
dataSeries.insert(index, index, xValue, yValue); 

You can also manipulate DataSeries values directly like this and update

var theRawXValues = (IList<double>)dataSeries.XValues;
theRawXValues[index] = 1234.5; 
// Notify that data changed 
dataSeries.InvalidateParentSurface(rangeMode: RangeMode.None, hasDataChanged: true)

However this could quickly make your dataseries unsorted, which you need to be careful of. Doing so can harm performance in line charts and cause unexpected results if you start manipulating the data directly.

Let me know if this helps,

Best regards,
Andrew

  • Nick Müller
    Hi Andrew, Thank you for your fast response. The method with “.RemoveAt” and “.Insert” is the one I came also up with. But your second method with accessing the XValues directly is also an interesting one. The thing here is, that we wouldn’t have to cache the PointMetaData and put it into the new Point. Would it be worth considering to extend the IDataSeries and IDataSeries3D Interface by an Update-Method like this: void Update(int index, TX x, TY y, (TZ z,) IPointMetadata metadata); (Also it could have all permutations of the Update method to Update e.g. only an X-Value or only a Y-Value) Best Regards, Nick
  • Andrew Burnett-Thompson
    The problem is that when you change your data we have to calculate properties such as the distribution of your data to choose the best and fastest algorithms internally to SciChart. If you change an x value and make the series unsorted, our code needs to know that and so we constrain your through the Api rather than allow you to manipulate data directly. We could add an overload for Update with x value, I don’t see a problem with it, or if you have the source code you could add it yourself. Is the remove / insert method not working or too slow? I don’t like to make api changes unless necessary.
  • Nick Müller
    Right now I think the remove / insert method should work fine. Until now I don’t think that we have any Performance inssues with the 2D and 3D Charts. The Question for the API Extention would just make our code a little more prettier because every DataSeries can be Updated the same way.
  • Andrew Burnett-Thompson
    Cool thanks Nick. For now add an extension method to cleanup your API. If it becomes a bottleneck we can review on our side.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies