Creating a graph without drawing it

I would like to creat TMultigraph, and write it to a root file and to pdf, but without displaying it.
That can be achived by not call TApplication->Run in my main routine, but that is bit of a hack, and produces a lot of error messages when run on a remote server.

T code look mor r less like this (its part of a larger and more complex set of code )

TCanvas *c = new TCanvas();
TMultiGraph *m = new TMultiGraph();

/*

  • Fill “m” with data
    */

c->cd():
m->Draw();
c->Write();
c->Print(“myplot.pdf”);

I can aloso show the plot If Im using TAppplication (this is compiled code not a macro)

This works fine, and I get the plots that I want both in pdf and root format, however when I run the softwarer on a remot build server, (without a display), then I get a lot of messages on the form.

Failed to open default display.
Failed to open default display.
Failed to open default display.
Failed to open default display.
,…

For each tijme I call Draw, however if I dont call m->Draw() then the multigraph is not attached to the TCanvas, and not written to file.

I wonder if its possible to create the graph and everything, and write it to file the same way as shown above, but without attemting to plot it on the screen

#include “TROOT.h”
// …
gROOT->SetBatch(kTRUE);