#include void macro_ex() { TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500); c1->SetFillColor(42); c1->SetGrid(); const Int_t max = 10; Double_t x[max]; Double_t y[max]; Double_t bw; Double_t c=0; x[0]=0; y[0]=0; stringstream temp; string datetime; const char *p; 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) { if (i==max){ i=0; gr->Set(i); } t = time(0); timeinfo = localtime ( &t ); temp << timeinfo->tm_hour << ":" << timeinfo->tm_min <<":" << timeinfo-> tm_sec; datetime = temp.str(); p = datetime.c_str(); x[i] = t; if (i%2 == 0) { // only to draw triangles y[i] = 2000; } else { y[i] = 2; } gr->SetPoint(i,x[i]-x[0],y[i]); if (i==0) { gr->GetXaxis()->Set(1,-0.1,0.1); } else { bw = ((x[i]-x[0])/(i+1))/2.; gr->GetXaxis()->Set(i+1,-bw,x[i]-x[0]+bw); } gr->GetXaxis()->SetNdivisions(-(i+1)); /// The value of "p" is wrong, it cumulates all the dates. This should be revisited /// gr->GetXaxis()->SetBinLabel(i+1,p); /// This kind of loop is neede to define the labels. for (Int_t j=1; j<=i+1; j++) { gr->GetXaxis()->SetBinLabel(j,Form("j=%d",j)); } c1->Update(); gSystem->Sleep(1000); i= i+1; } }