normally, in HTML, images (such as your graph) are requested separately from the "text",
so it would have to be a different script, and the parameters have to come in via URL parameters,
which mandates parameter checking, because anyone could call the "image script" by hand.
It is possible to incorporate images directly with <img src="data:... (see
So you could call your graph generator directly as a subroutine (with already checked parameters).
Of course, your subroutine would have to (base64) encode the image.