SetTimeDisplay on a TMultiGraph

Hi,

I am trying to set the X-axis to a time display on a TMultiGraph from inside a compiled program. Doesnt seem to work… The following program for example hits the debug macros…
[color=#FF0040][size=85]root [2] multiGraphTimeAxisTest()
DEBUG :Histogram NULL!!
DEBUG :XAxis NULL!![/size][/color]

The program:

[code]
// multiGraphTimeAxisTest.c
#include <TCanvas.h>
#include <TMultiGraph.h>
#include <TGraph.h>
#include <TAxis.h>
#include <TFrame.h>
#include <utility/TErrorMsg.h>

void multiGraphTimeAxisTest()
{
Double_t *x = new Double_t[1000];
Double_t *y1 = new Double_t[1000];
Double_t *y2 = new Double_t[1000];

for(int k=0;k<1000;k++)
{
	x[k] = 2*k;
	y1[k]= k%100;
	y2[k]= k%150;
}
TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);

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

TMultiGraph *mg = new TMultiGraph();
TGraph * gr1 = new TGraph(1000,x,y1);
gr1->SetLineColor(2);
gr1->SetLineWidth(1);
//gr1->SetTitle("a simple graph");
//gr1->GetXaxis()->SetTitle("X title");
//gr1->GetXaxis()->SetTimeDisplay(1);

//gr1->GetYaxis()->SetTitle("Y title");
//gr1->Draw("AL");

TGraph * gr2 = new TGraph(1000,x,y2);
gr2->SetLineColor(3);
gr2->SetLineWidth(1);
mg->Add(gr1);
mg->Add(gr2);

if(mg->GetHistogram()==0) DEBUG("Histogram NULL!!");
if(mg->GetXaxis()==0) DEBUG("XAxis NULL!!");
else mg->GetXaxis()->SetTimeDisplay(1);

mg->Draw("AL");

// TCanvas::Update() draws the frame, after which one can change it
c1->Update();
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(12);
c1->Modified();

delete [] x;
delete [] y1;
delete [] y2;

}[/code]

Modify your macro adding one line:

[code]// …
mg->Add(gr2);

mg->Draw(“AL”); // this line is added

if(mg->GetHistogram()==0) DEBUG(“Histogram NULL!!”);
if(mg->GetXaxis()==0) DEBUG(“XAxis NULL!!”);
else mg->GetXaxis()->SetTimeDisplay(1);

// mg->Draw(“AL”); // this line can be removed
// …[/code]

Thanks pepe… that helps…