How to use "RemoveFromBeginning" in non-bind?

A forum dedicated to WPF version of LightningChart Ultimate.

How to use "RemoveFromBeginning" in non-bind?

Postby coldsun1982 » Mon Apr 22, 2019 2:47 pm

Hi, I use non-bindable wpf Charting, I can add points use "_chart.ViewXY.PointLineSeries[0].AddPoints(points, false);", and I can get the count of points use "_chart.ViewXY.PointLineSeries[0].PointCount".
When count > 500, I want to remove the points at index of 0. Now I don't konw how to do, I can't find and use the command "RemoveFromBeginning", becasue the command is in semi-bind or binable.
And I don't want to use "DropOldSeriesData" also, because I want to zoom in or out.
Please tell me how to remove the point just like "RemoveFromBeginning", thank you.
coldsun1982
 
Posts: 12
Joined: Thu Feb 28, 2019 1:57 am

Re: How to use "RemoveFromBeginning" in non-bind?

Postby Arction_LasseP » Tue Apr 23, 2019 1:18 pm

Hello,

The data points are stored as an array, which works in a similar way as any array in C#. There are other ways besides DropOldSeriesData to remove the first data point. PointLineSeries (and HighLowSeries) has DeletePointsBeforeX -method which removes all points before given x value.

Code: Select all
_pointLineSeries.DeletePointsBeforeX(xValue);


Another way is to convert the data point array to a list, remove the point, and convert the list back to an array. Here is an example code, in which the first point is removed and a new one is added to the end of the data list/array.

Code: Select all
List<SeriesPoint> list = _chart.ViewXY.PointLineSeries[0].Points.ToList();
list.RemoveAt(0);

var data = new SeriesPoint(xValue, yValue);
list.Add(data);

_chart.BeginUpdate();
_chart.ViewXY.PointLineSeries[0].Points = list.ToArray();
_chart.EndUpdate();


Hope this is helpful.
Arction_LasseP
 
Posts: 39
Joined: Wed Mar 27, 2019 1:05 pm

Re: How to use "RemoveFromBeginning" in non-bind?

Postby coldsun1982 » Tue Apr 23, 2019 1:44 pm

Hi, as you said in the first method, I don't know the value of point[0]. if I used the DeletePointsBeforeX, It may be delete all smaller X value than given value. This is what I don't want to meet.
In your second method, It wiil slove my problem, Does this operation slow down the speed?Now, It read all points to a list, and add list to chart instead of delete directly.
If I use semi-bindable chart, I can use RemoveFromBeginning, How much speed difference does it have compared to non-bindable(read point to list, remove the index of list0, and add the list to chart)?
And I have a question: Does the command "RemoveFromBeginning" delete the point or delete PointLineSeries?
coldsun1982
 
Posts: 12
Joined: Thu Feb 28, 2019 1:57 am

Re: How to use "RemoveFromBeginning" in non-bind?

Postby Arction_LasseP » Wed Apr 24, 2019 8:18 am

Hello,

RemoveFromBeginning -method is usable with collections but not with arrays. This is why it is only available in Semi-bindable and Bindable version, since Non-bindable prefers arrays. It also shouldn't be any faster that the other methods provided above, as in general handling arrays is faster than handling collections. However, if you are having somewhere around 500 points at the time, the speed difference shouldn't be very significant.

Whether RemoveFromBeginning deletes points or series depends on the collection:

Code: Select all
_chart.ViewXY.PointLineSeries.RemoveFromBeginning(1); // Removes the first PointLineSeries in Semi-Bindable

YourPointsCollection.RemoveFromBeginning(1); // Removes the first point in Fully-bindable


DeletePointsBeforeX could still be used in your case. You can get the x-value of an index via _chart.ViewXY.PointLineSeries[0].Points[pointIndex].X and remove the points smaller than this. As in PointLineSeries, the x-values should be in ascending order, this should never delete any unwanted points. The only exception is that if a data point has the same x-value than the previous one, the previous point is not deleted.

Code: Select all
// Removes the first data point
_chart.ViewXY.PointLineSeries[0].DeletePointsBeforeX(_chart.ViewXY.PointLineSeries[0].Points[1].X);


Hope this helps.
Arction_LasseP
 
Posts: 39
Joined: Wed Mar 27, 2019 1:05 pm

Re: How to use "RemoveFromBeginning" in non-bind?

Postby coldsun1982 » Wed Apr 24, 2019 1:52 pm

Hi, as you said, If my x'value is random, the x-values may not be in ascending order or it may be the data point == the previous point, is the DeletePointsBeforeX not fit for me?
One more thing, how to use YourPointsCollection.RemoveFromBeginning(1) in full -bind? how to set YourPointsCollection to be related with the _chart.ViewXY.PointLineSeries.Point? Can YourPointsCollection use in semi-bind?
coldsun1982
 
Posts: 12
Joined: Thu Feb 28, 2019 1:57 am

Re: How to use "RemoveFromBeginning" in non-bind?

Postby Arction_LasseP » Thu Apr 25, 2019 7:43 am

Hi,

DeletePointBeforeX could be used if the datapoint.x == previouspoint.x case is handled. Here is an example to give you the idea:

Code: Select all
if (_chart.ViewXY.PointLineSeries[0].Points[0].X == _chart.ViewXY.PointLineSeries[0].Points[1].X)
{
        _chart.ViewXY.PointLineSeries[0].Points[0].X -= 0.000001;
}
_chart.ViewXY.PointLineSeries[0].DeletePointsBeforeX(_chart.ViewXY.PointLineSeries[0].Points[1].X);


However, DeletePointBeforeX only works if the x-values are in progressive order. If you know that this is not the case in your application, that there will be situations where datapoint.x < previouspoint.x, it is recommended to use FreeformPointLineSeries instead. Many of PointLineSeries's properties (like DeletePointBeforeX) are designed to work with these progressive x-values. FreeFormPointLineSeries doesn't have any constrains like this, though it is slightly slower performance-wise compared to PointLineSeries. However, the difference should be noticeable only with very large amounts of points.

If you decide to use FreeFormPointLineSeries, note that DeletePointBeforeX is not available with it. Converting array to list and back to array method is still usable. Alternatively, Freeform's PointCountLimit -property could be used. It limits the amount of points and automatically drops the old points if the limit is exceeded (User's Manual chapter 5.8).


YourPointCollection is a name of a SeriesPointCollection that could be created in fully-bindable. It can be used by creating a DependencyProperty and binding it to PointLineSeries points in xaml. If you have access to our demo examples, the use of DependencyProperties are shown there pretty well. Here is an example:

Code: Select all
Points = new SeriesPointCollection();

public static readonly DependencyProperty PointsProperty =
         DependencyProperty.Register(
            "Points",
            typeof(SeriesPointCollection),
            typeof(ExampleSimplePointLineSeriesViewModel)
         );
public SeriesPointCollection Points
      {
         get { return GetValue(PointsProperty) as SeriesPointCollection; }
         set { SetValue(PointsProperty, value as Object); }
      }

// In xaml
<lcub:PointLineSeries Points="{Binding Points}"/>


Semi-bindable does not support per-data-point binding so SeriesPointCollections are not useful there.

Hope this is helpful.
Arction_LasseP
 
Posts: 39
Joined: Wed Mar 27, 2019 1:05 pm

Re: How to use "RemoveFromBeginning" in non-bind?

Postby coldsun1982 » Thu Apr 25, 2019 12:06 pm

Thank you for your help.
coldsun1982
 
Posts: 12
Joined: Thu Feb 28, 2019 1:57 am


Return to LightningChart Ultimate WPF

Who is online

Users browsing this forum: No registered users and 9 guests

cron