Page 1 of 1

Deleting points that are not on the screen

Posted: Tue Mar 28, 2006 9:18 am
by 8128839
Hi,

I'm trying to delete points as they are removed from the screen. The problem is, I don't know how I can find the location of the earliest point.

From the example...
tChart1[0].YValues.Value[0] =103.96; MessageBox.Show(tChart1[0].YValues.First.ToString());

I can delete point 0, but after that, is that location ever used again? Is there a way that I can use a "get_FirstPoint" style function, or another way to do it that you could recommend.

I never know how many points I will need to remove each time, as every second, between 0 and 3 points are added, so I'd like to be able to use some code like: -

Code: Select all

minimum = x value of last point being displayed
while (first point < minimum)
   delete first point
That code will be called every second.

Is there a way to do that, or a better way that anyone knows.

Cheers

Posted: Tue Mar 28, 2006 9:35 am
by narcis
Hi andyb,

Yes, you can use something like the code below. This method uses the series Delete method which has several overrides. In that case it always removes the first point in the series.

Code: Select all

    private int count = 0;
    private int MaxDisplayedPoints = 100;

    private void timer1_Tick(object sender, EventArgs e)
    {
      Random randY=new Random();

      for (int i = 0; i < 3; ++i)
      {
        count++;
        line1.Add(count,randY.Next());
      }

      while (line1.XValues[j] < count - MaxDisplayedPoints) line1.Delete(j);
    }

Posted: Tue Mar 28, 2006 10:10 am
by 8128839
Thanks Narcis,

That sounds like what I need. Where are you getting j from?

Posted: Tue Mar 28, 2006 10:23 am
by narcis
Hi andyb,

Sorry, my fault. I originally used a variable called j but then I noticed it wasn't necessary so the code would be:

Code: Select all

    private int count = 0;
    private int MaxDisplayedPoints = 100;

    private void timer1_Tick(object sender, EventArgs e)
    {
      Random randY=new Random();

      for (int i = 0; i < 3; ++i)
      {
        count++;
        line1.Add(count,randY.Next());
      }

      while (line1.XValues[0] < count - MaxDisplayedPoints) line1.Delete(0);
    }