Render TH1D to PNG format

How can I render a TH1D object to a PNG file,
without passing for x/the window manager?

Now i use
TCanvas*newcanvas=new TCanvas();
TH1D->Draw();
newcanvas->SaveAs(“output.png”);

File is created, but TCanvas is rendered on screen.
Is there a trick to create png “without using x” ?

Thanks
Yawn

run in batch mode

root -b -q myscript.C or in your program add

gROOT->SetBatch();
Rene

That’s surely a Frequently Asked Question.
I have added it as such here:
root.cern.ch/drupal/faq#n674