470,594 Members | 1,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

easiest way to create a graph?

I'm looking at adding some basic line graphs to a page. Enabled gd, and
started in on pear::image_graph. Just wanting to start simple, I created a
new graph, set the background color, and displayed it. I also added the
header call to set the content for jpeg, but all I get is a bunch of
characters on my screen.

Here's the (excerpted) simple code:

Header ("Content-type: image/jpeg");

$defwidth = 300;
$defheight = 200;
$mychart = new Image_Graph($defwidth, $defheight);
$mychart->setBackgroundColor("white");
// build the chart

imagejpeg($mychart->getGDImage());

I also couldn't figure out what setBackgroundColor expected, Are there any
samples about for this?

Thanks,
Greg
Jul 17 '05 #1
3 1472
Greg Bryant <br**********@yahoo.com> wrote in
news:Xn**********************************@199.45.4 9.11:
I'm looking at adding some basic line graphs to a page. Enabled gd,
and started in on pear::image_graph. Just wanting to start simple, I
created a new graph, set the background color, and displayed it. I
also added the header call to set the content for jpeg, but all I get
is a bunch of characters on my screen.


I get it. You need to have the <img...> tag to get an image in the first
place, and can only get the image from the gd library indirectly. I think
the design is a bit off. If I'm forced to put the img source in different
script, it makes my database access more complex than necessary, or I can
drop it in a file, which just slows down the script. Yuck. I would much
prefer to directly use the imagepng call as the img source (i.e. <img
src=imagepng(resource)> ).

Oh well. At least I have a nice white box now!

Greg

Jul 17 '05 #2
Greg Bryant wrote:
Greg Bryant <br**********@yahoo.com> wrote in
news:Xn**********************************@199.45.4 9.11:
I'm looking at adding some basic line graphs to a page. Enabled gd,
and started in on pear::image_graph. Just wanting to start simple, I
created a new graph, set the background color, and displayed it. I
also added the header call to set the content for jpeg, but all I get
is a bunch of characters on my screen.


I get it. You need to have the <img...> tag to get an image in the first
place, and can only get the image from the gd library indirectly. I think
the design is a bit off. If I'm forced to put the img source in different
script, it makes my database access more complex than necessary, or I can
drop it in a file, which just slows down the script. Yuck. I would much
prefer to directly use the imagepng call as the img source (i.e. <img
src=imagepng(resource)> ).

Oh well. At least I have a nice white box now!

Greg


Hee Greg: 1 tip:

If you think your imagescript is producing errors, change the header to
text/html, and call the image directly.
In that way you often get a lot of notices/erros that you would otherwise
have to extract from some logfile.

It helped me a lot to debug quicker.

Regards,
Erwin
Jul 17 '05 #3
Erwin Moller
<si******************************************@spam yourself.com> wrote in
news:41***********************@news.xs4all.nl:

Hee Greg: 1 tip:

If you think your imagescript is producing errors, change the header
to text/html, and call the image directly.
In that way you often get a lot of notices/erros that you would
otherwise have to extract from some logfile.

It helped me a lot to debug quicker.

Regards,
Erwin


That's a good idea - thanks.

If anyone knows of any examples of the pear::image_graph stuff out there,
I'm still looking for some. Even the blog comments like the main php
site's docs have are handy, but either aren't done for pear or no one uses
it.

Greg
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Lilith | last post: by
7 posts views Thread by Wolfgang Kreuzer | last post: by
1 post views Thread by mahnovetsky | last post: by
1 post views Thread by entropy123 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.