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; }
|
|---|