Why this TGraph is not being drawn?

Hi,
I’m new to ROOT and C++. I have already done some graphs in ROOT, but I don’t understand why this code is not working:

void test(){
	
	Double_t x[] = {1,2,3,4,5,6};
	Double_t y[] = {1,2,3,4,5,6};
	
	Int_t len = sizeof(x)/sizeof(x[0]);
	
	TCanvas *c1 = new TCanvas();
	
	TGraph *gr1 = new TGraph();
	
	
	Int_t i;
	for (i=0; i<len+1; ++i){
		cout << x[i] << "\n";
		gr1 -> AddPoint(x[i], y[i]);
	}
	
	
	gr1 -> Draw("p");
	
	
	c1 -> Print("e.png");
}

I get a white .png and the cout:
1
2
3
4
5
6
6.95313e-310 // I don’t understand this value!


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24/06
Platform: Debian (Windows Subsystem for Linux)
Compiler: Not Provided


Hi Abel!

Print i in your loop and you’ll understand. There’s nothing ROOT-related here, you’re just getting the for loop wrong:

	for (i=0; i<len; ++i){

gr1->Draw("p") doesn’t actually draw axes etc; check the doc: ROOT: TGraphPainter Class Reference - you probably want "ap"?

I hope that helps!

Axel