TGraph : behavior at the end of the array

Hello,
I am using TGraph to plot metrics in time.
In order to be able to update the plot even when the array associated to the TGraph is not completely filled I do:

Double_t x[max], y[max];
x[0] = 0;
y[0] = 0;
gr = new TGraph(1, x, y);

and every time that I assign a value to x[i] and y[i] I do:
gr->SetPoint(i, x[i], y[i]);

when I arrive to the end of the array, that means i=max, I reinitialize i to 0 and start again filling the array.
The result on the plot is that when I assign again x[0] and y[0], the curve of the plot is connecting y[0] which is at the end of the plot and y[1] which is at the beginning.
Is there a way to avoid this?
Thank you
Adriana

Can you send a small macro reproducing what you described ?

In attachment you can find an example.
Thanks
macro_ex.C (915 Bytes)

I suggest the following:

void macro_ex() {
   TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);

   c1->SetFillColor(42);
   c1->SetGrid();

   TStopwatch sw;
   sw.Start();

   const Int_t max = 10;

   Double_t x[max];
   Double_t y[max];

   Double_t c=0;
   x[0]=0;
   y[0]=0;

   gr = new TGraph(1,x, y);
   gr->SetMarkerStyle(21);
   gr->SetTitle("Time graph");
   gr->GetXaxis()->SetTitle("X title");
   gr->GetYaxis()->SetTitle("Y title");
   Int_t i =0;

   gr->Draw("ALP");  

   while(1){

      sw.Stop();
      c=sw.RealTime();

      sw.Continue();

      x[i] = c;

      if (i%2 == 0) {  // only to draw triangles
         y[i] = 2000;
      } else {
        y[i] = 2;
      }

      gr->SetPoint(i,x[i],y[i]);

      c1->Update();
      gSystem->Sleep(1000);
      i= i+1;

      if (i==max) {
         i=0;
         gr->Set(i);
      }
   }
}