How to render graphics in a file, without displaying the image on the screen?

Run in batch mode:

root -b -q myscript.C

or in your program add:

gROOT->SetBatch();