[ROOT] Re:

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Aug 08 2000 - 17:16:13 MEST


TGraph::Draw creates an histogram to set the range and draw the axis.
In your exaple the histogram does not exists yet at the point where you call
TGraph::GetHistogram. This functions returns a null pointer.
I have modified your code below to get what you want.
Note that it would be simpler to write a macro using the standard root
executable
rather than writing your own main program.

Rene Brun


kamps wrote:
> 
> Hello,
> Is it correct that histogram like attributes of a graph must be handled by
> the GetHistogram()
> function ? The program below runs under WINNT, visual C++ 6.0, root 2.24/05,
> but crashes if
> I include the line that is commented out.
> 
> #include <TRoot.h>
> #include <TCanvas.h>
> #include <TPad.h>
> #include <TApplication.h>
> #include <TGraph.h>
> #include <TH1.h>
> 
> extern void InitGui();
> VoidFuncPtr_t initfuncs[] = {InitGui, 0};
> TROOT root("rint","The ROOT Interactive Interface", initfuncs);
> 
> int main()
> {
>         TApplication* pRootApp = new TApplication("RootApp",0,0);
>         TCanvas* c = new TCanvas("c1","bla",200,10,600,400);
>         TPad *pad1 = new TPad("pad1","The pad",0.05,0.52,0.95,0.97);
> 
>         c->SetGrid();
> 
>         float x[3];
>         float y[3];
> 
>         x[0] = 0.0;
>         y[0] = 0.0;
> 
>         x[1] = 0.5;
>         y[1] = 0.5;
> 
>         x[2] = 0.9;
>         y[2] = 0.9;
> 
>         TGraph graph(3,x,y);
>         graph.SetTitle("linear");
          graph.Draw("al");  //<===specify the drawing option "a"
          c->Update(); //<<=======new
          graph.GetHistogram()->SetLabelSize(1e-1);
> 
          c->Modified();
>         c->Update();
> 
>         while(1)
>                 ;
> 
>         return 0;
> }



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:31 MET