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

Re: draw a graph

by jrsimmon (Hermit)
on Jul 31, 2009 at 16:24 UTC ( [id://784934]=note: print w/replies, xml ) Need Help??


in reply to draw a graph

Where is your shebang? Where is your CGI object? Where are your strictures?

Updated with working example:
#!C:\perl\bin\perl.exe -wT #always use strict; use CGI ':standard'; #tell CGI to print fatal errors to the browser use CGI::Carp qw(fatalsToBrowser); use GD::Graph::bars; #you need to actually create a cgi object, not just include the module my $q = new CGI; # Both the arrays should same number of entries. my @data = (["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], [23, 5, 2, 20, 11, 33, 7, 31, 77, 18, 65, 52]); my $mygraph = GD::Graph::bars->new(500, 300); $mygraph->set( x_label => 'Time taken (Hrs) for compilation', y_label => 'Environments', title => 'Production taken in the Week of $file', ) or warn $mygraph->error; open FH, "> graph.png"; binmode FH; print FH $mygraph->plot(\@data)->png; close FH; #this is all wrong #You're mixing your methods of printing the image. If you're going to #print it directly, there's no need to save it to file. But then you #can't be printing text to the screen first. If you're going to print + it #inside an image tag and referencing a file, you can't just dump the p +ng data #to the screen. #-- you need to look at the cgi doc again #print "Content-type: image/png\n\n"; #print "raja\n"; #print $myimage->png; PRINT_FROM_FILE(); #----OR---- #PRINT_IMAGE_DIRECTLY($mygraph); sub PRINT_FROM_FILE{ #print a simple page referencing the file you created earlier print header , start_html , img ({src=>"/graph.png"}) , end_html; } sub PRINT_IMAGE_DIRECTLY { my $mygraph = pop(@_); # my $myimage = $mygraph->plot(\@data) or die $mygraph->error; print header('image/png') , $mygraph->plot(\@data)->png; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://784934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2025-02-16 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found