Accessing stats-box from fit: Illegal pointer error

The problem is if you fit a TGraph with default settings no stats box is created and therefore it cannot be accessed. After you call gStyle->SetOptFit(x); with a non-zero value for x, the stats box is created and can be accessed with (TPaveText*)fivgraph->FindObject("stats")
Further information on the SetOptFit function can be found here: ROOT: TStyle Class Reference

Maybe this topic is also helpful it is a somehow related topic: