Dear all,
I am trying to plot a simple plot using root in c++ but getting an error after execution as follows:
anaIntSkeleton.cc:1929: error: ‘gr’ was not declared in this scope
anaIntSkeleton.cc:1929: error: expected type-specifier before ‘TGraph’
anaIntSkeleton.cc:1929: error: expected ‘;’ before ‘TGraph’
anaIntSkeleton.cc:1931: error: expected type-specifier before ‘TGraph’
anaIntSkeleton.cc:1931: error: expected ‘;’ before ‘TGraph’
anaIntSkeleton.cc:1942: error: invalid use of incomplete type ‘struct TFrame’
/usr/include/root/TVirtualPad.h:52: error: forward declaration of ‘struct TFrame’
Please let me know what is my mistake in writing this code.
TCanvas *c_imr = new TCanvas("c_imr","A Simple Graph Example",200,10,700,500);
c_imr->SetFillColor(42);
c_imr->SetGrid();
const Int_t n = 20;
double x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
printf(" i %i %f %f \n",i,x[i],y[i]);
}
gr = new TGraph(n,x,y);
gr = new TGraph(n,x,y);
gr->SetLineColor(2);
gr->SetLineWidth(4);
gr->SetMarkerColor(4);
gr->SetMarkerStyle(21);
gr->SetTitle("a simple graph");
gr->GetXaxis()->SetTitle("X title");
gr->GetYaxis()->SetTitle("Y title");
gr->Draw("ACP");
c_imr->Update();
c_imr->GetFrame()->SetFillColor(21);
c_imr->GetFrame()->SetBorderSize(12);
c_imr->Modified();
c_imr->Print(".ps");