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

hai monks, i have one more clarification on creating graph images, i want ot set heading for the graph which i was create. i tried by this way

print "Content-type: image/png\n\n"; my @data = ([@xaxiss],[@yaxiss]); use GD::Graph::bars; use GD::Image; $width=$xaxiss[0]; $height=$xaxiss[$#xaxiss]; #image -1 graph my $mygraph = GD::Graph::bars->new(800,600); # $mygraph->set_legend('Show gene details'); $mygraph->set( title => "$pairs[0]", x_label => "@xaxis", x_labels_vertical => 90, bar_width => 10, bar_spacing => 1, show_values => 1, dclrs => ['lorange'] , axislabelclr => 'red', # logo => 'bgcolor1.png', /corect on/ # logo_resize =>5.5, transparent => 1, shadowclr => 'gray', shadow_depth =>3, borderclr=>'green', transparent => '0', bgclr => 'lbrown', boxclr => 'lbrown', fgclr => 'blue', cycle_clrs => '1', ) or warn $mygraph->error; $mygraph->set_title_font(GD::gdGiantFont); #$mygraph->set_legend_font(GD::gdGiantFont); $mygraph->set_x_axis_font(GD::gdMediumBoldFont); $mygraph->set_y_axis_font(GD::gdMediumBoldFont); $mygraph->set_values_font(GD::gdSmallFont); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; open(OUT,">/tmp/img1.png"); binmode OUT; print OUT $myimage->png; close OUT; &head_1; print $myimage->png; #image-2 for heading sub head_1{ sub InitColors { my($im) = $_[0]; # Allocate colors $white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $red = $im->colorAllocate(255,0,0); $blue = $im->colorAllocate(0,0,255); $green = $im->colorAllocate(0, 255, 0); $brown = $im->colorAllocate(255, 0x99, 0); $violet = $im->colorAllocate(255, 0, 255); $yellow = $im->colorAllocate(255, 255, 0); } use GD; # Create a new image $im = new GD::Image(500, 80); # Allocate some colors &InitColors($im); # Make the background transparent and interlaced $im->transparent($white); $im->interlaced('true'); $im->rectangle(0, 0, 500, 79, $white); $x1 = 10; $y1 = 20; # Draw text in a TTF font # $font = "/usr/X11R6/lib/X11/fonts/TTF/luxisri.ttf"; # $im->stringFT($red, $font, 15, 0, $x1, $y1, "A TTF font"); #$anotherfont = "/usr/share/fonts/default/TrueType/starbats.ttf"; $anotherfont = "/usr/share/fonts/ko/TrueType/hline.ttf"; $im->stringFT($black, $anotherfont, 30, 0, $x1, $y1 + 40, "Show gene d +etails"); # Open a file for writing open(PICTURE, ">/tmp/picture.png") or die("Cannot open file for writin +g"); # Make sure we are writing to a binary stream #binmode PICTURE; # Convert the image to PNG and print it to the file PICTURE #print PICTURE $im->png; print $im->png; close PICTURE; }

in the above code the first image-1 indicate the bar chart generated for the data and the second one image-2 which is called by using subroutine is the heading for that graph, but while using this method only one image is displaying on the screen, is their any sugession for this or any different idea on about it.

------------------------------------------------------

hi monks, i tried to make the two separate images as single image by changing the code as follows is it correct.

--new code-- print "Content-type: image/png\n\n"; sub InitColors { my($im) = $_[0]; # Allocate colors $white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $red = $im->colorAllocate(255,0,0); $blue = $im->colorAllocate(0,0,255); $green = $im->colorAllocate(0, 255, 0); $brown = $im->colorAllocate(255, 0x99, 0); $violet = $im->colorAllocate(255, 0, 255); $yellow = $im->colorAllocate(255, 255, 0); } my @data = ([@xaxiss],[@yaxiss]); use GD::Graph::bars; use GD::Image; $width=$xaxiss[0]; $height=$xaxiss[$#xaxiss]; #image -1 graph my $mygraph = GD::Graph::bars->new(800,600); $mygraph->set_legend('Show gene details'); --changed portion-- $anotherfont = "/usr/share/fonts/ko/TrueType/hline.ttf"; $mygraph->set_stringFT('black', $anotherfont, 30,40, "Show gene detail +s"); ---change ends--- $mygraph->set( title => "$pairs[0]", x_label => "@xaxis", x_labels_vertical => 90, bar_width => 10, bar_spacing => 1, show_values => 1, dclrs => ['lorange'] , axislabelclr => 'red', # logo => 'bgcolor1.png', /corect on/ # logo_resize =>5.5, transparent => 1, shadowclr => 'gray', shadow_depth =>3, borderclr=>'green', transparent => '0', bgclr => 'lbrown', boxclr => 'lbrown', fgclr => 'blue', cycle_clrs => '1', ) or warn $mygraph->error; $mygraph->set_title_font(GD::gdGiantFont); #$mygraph->set_legend_font(GD::gdGiantFont); $mygraph->set_x_axis_font(GD::gdMediumBoldFont); $mygraph->set_y_axis_font(GD::gdMediumBoldFont); $mygraph->set_values_font(GD::gdSmallFont); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; #open(OUT,">/tmp/img1.png"); #binmode OUT; #print OUT $myimage->png; #close OUT; print $myimage->png;

while compiling this code it show the error message as follows,
--Error code-- http://10.188.12.27/cgi-bin/msgs/siva_graph/ graph1cgi.pl?A_thaliana&2&1&7473&NC_003070sNC_003071&6973s4403&
by sanku thanks in advance any sugessions please?????

Replies are listed 'Best First'.
Re: Using an image as a header with GD::Graph
by davorg (Chancellor) on Nov 07, 2006 at 15:22 UTC

    It looks like you're just printing out two images, one after the other, both in response to a single HTTP request.

    That won't work. You can only send a single image back for each request. You will need to either combine the two images into one (and I'm sure that GD will allow you to do that) or have two separate requests, one for the header and one for the graph.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Yeah, when I need a bunch of graphs on a page, what I usually do is to write multiple images to distinct files (as it seems you were trying) and then refer to them each using an <img> tag in a larger HTML document.

Re: Using an image as a header with GD::Graph
by ptum (Priest) on Nov 07, 2006 at 15:21 UTC

    Why not just use the set_title('My Title') method and incorporate the title into the bar graph?

    Update: When you make a change to your original node, please annotate it as such, using a bold Update tag. Additionally, I notice that you are creating your graph using data from arrays @xaxiss and @yaxiss, yet those are previously undeclared. Where is your graph data coming from? Why aren't you using strict? You might want to consider backing up and using sample code from the synopsis section of GD::Graph. Get that working, and then modify it one attribute at a time until you have what you want.

Re: Using an image as a header with GD::Graph
by andyford (Curate) on Nov 07, 2006 at 15:23 UTC
    It looks like you tried printing to your filehandle PICTURE, commented it out and then printed the png to STDOUT. The one with the PICTURE filehandle should have been what you wanted if $im had anything in it. What output did you get when you printed $im to STDOUT?
    # Open a file for writing open(PICTURE, ">/tmp/picture.png") or die("Cannot open file for writin +g"); # Make sure we are writing to a binary stream #binmode PICTURE; # Convert the image to PNG and print it to the file PICTURE #print PICTURE $im->png; print $im->png; close PICTURE;

    andyford
    or non-Perl: Andy Ford