Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Multiple GD::graphs in one web page

by mhearse (Chaplain)
on Apr 06, 2005 at 16:26 UTC ( #445429=perlquestion: print w/replies, xml ) Need Help??

mhearse has asked for the wisdom of the Perl Monks concerning the following question:

What is the best way to have multiple GD::Graphs on one web page? I found an earlier node, but it seemed to indicate it wasn't possible. Well, it did say that they all could be merged into one. Basically I want to dynamically generate 4 seperate graphs on the fly (whenever a link is clicked) and display them all on one web page. My current method is to generate each graph seperately, saving it to a http world writable directory (bad I know). Then include the images from within html. Is there a better way to do this? Thanks much.

Replies are listed 'Best First'.
Re: Multiple GD::graphs in one web page
by brian_d_foy (Abbot) on Apr 06, 2005 at 17:41 UTC

    If you are already creating them dynamically, you can turn that portion into a separate CGI script. Use that CGI script as the SRC value in the IMG tag.

    <img src="" />

    Your CGI script has to return the right MIME type, such as "image/png" or something else.

    Once you put those things in IMG tags, you just use the tags in the HTML like any other IMG tag.

    brian d foy <>
      Thanks, this worked. As you suggested, I used the CGI script itself as the image. Passing an argument of 1..4 in order to tell the script what image I wanted.
      <img src="/cgi-bin/trend.cgi?image=1"> <img src="/cgi-bin/trend.cgi?image=2"> <img src="/cgi-bin/trend.cgi?image=3"> <img src="/cgi-bin/trend.cgi?image=4">
      The CGI script, or course, accepted the param and returned the corresponding image.
Re: Multiple GD::graphs in one web page
by SciDude (Friar) on Apr 06, 2005 at 16:41 UTC

    For a recent customer service data project, I needed several GD::Graphs and simply duplicated my call to individual code for each graph:

    print "<img src=>";
    Replicate the above link for each graph needed. Each graph can then be customized by code, for example:
    #!/usr/bin/perl -w use GD::Graph::bars; ...get data here... my $mygraph = GD::Graph::bars->new( 600, 350 ); $mygraph->set( dclrs => [qw(green pink blue cyan)] ); $mygraph->set( x_label => 'Section', y_label => 'Satisfaction', title => 'Customer Service By Question', bar_spacing => '5', ) or warn $mygraph->error; my $myimage = $mygraph->plot( \@graph )->png; print "Content-type: image/png\n\n"; print $myimage;

    I think you will find other examples similiar to this one with a super search.

    The first dog barks... all other dogs bark at the first dog.
Re: Multiple GD::graphs in one web page
by nikos (Scribe) on Apr 06, 2005 at 16:40 UTC
    You can combine them using GD into one image and display it. This way you do not need to create separate files. Your script will return one image only.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://445429]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2019-11-13 22:32 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (74 votes). Check out past polls.