I am reading samples from a serial port continously and I want to show the last 400 samples in a graph.
So when the number of received samples becomes 400 I should shift the myPointFs
List to left by 1 and add the last received sample
to the end of it. My below code works successfully while the first 400 samples.
List<PointF> myPointFs = new List<PointF>();
uint sampleNumber = 0; PointF Current_PointFs;
private void UpdateVar(object sender, EventArgs e){
...
Current_PointFs = new PointF((float)(sampleNumber), (float)newSample);
if (sampleNumber < 400)
{
myPointFs .Add(Current_PointFs);
++sampleNumber;
}
else
{
myPointFs = myPointFs .ShiftLeft(1); //ShiftLeft is an Extension Method
myPointFs.Add(Current_PointFs);
}
if (myPointFs.Count >= 2)
{
Configure_Graphs();// using Graphics.DrawLines(thin_pen, myPointFs.ToArray()) to draw chart
}
}
But after that the first 400 samples recieved, I need to substract 1 from myPointFs[i].X
to shift X-axis to left by 1. Maybe a way is to run a for loop.
How can I implement it? Or is there any more elegant way? Or something that it exists out-of-the-box in C#?
Edit: (To make my question more clear)
myPointFs
contains something like this:
myPointFs[0] = {X = 1, Y = 21}
myPointFs[1] = {X = 2, Y = 50}
myPointFs[2] = {X = 3, Y = 56}
now I will remove the first element by shifting left by 1 and add a new sample to the end.
myPointFs[0] = {X = 2, Y = 50}
myPointFs[1] = {X = 3, Y = 56}
myPointFs[2] = {X = 4, Y = 68}
But I need finally something like this:
myPointFs[0] = {X = 1, Y = 50}
myPointFs[1] = {X = 2, Y = 56}
myPointFs[2] = {X = 3, Y = 68}