You'd have to do some sort of redirect to the page that displays the page.
So you could do
header ("Location: http://www.domain.ext/showgraph.php");
and that redirects automatically, before you call that line, run the inserting portion of your script.
The other method I would say would be to use a meta tag to redirect. This way you could put like "Generating your graph.. please wait"
You also might be able to try to stall your script to wait with sleep(). So put the insert code above, then sleep() for a second or two below.
I hope I helped... good luck
-Justin