Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Good day monks I have been working with doing a bandwidth test that prints out html for a few days now and with the help of a fellow monk I was able to get a working test to run, but I am now wanting to get the thing to use GD::Graph to make a pretty image..
I have read the perldoc on GD::Graph and think I have it right but I am getting this error "can't call method "plot" on an undefined value". Now from what I can see there should be no issue, but I must be missing something. Below is my code for you to look over and let me know if I am just missing something.
#!/usr/bin/perl -w use warnings; use strict; use Time::HiRes qw ( gettimeofday ) ; use CGI qw(:standard); use GD::Graph::hbars; use CGI::Carp (fatalsToBrowser); my $data = "E"x1020; #start with using 1k blocks shall we? my %cgi_vars; foreach my $pair ( split ( "&", $ENV{'QUERY_STRING'} ) ) { my ( $var, $val ) = split ("=", $pair); $cgi_vars{$var} = $val; } #cgi headers: print "content-type: text/html\n\n"; #take time my ( $start_seconds, $start_microseconds ) = gettimeofday; print "Start Seconds:$start_seconds Start MicroSeconds:$start_microsec +onds<BR/>\n"; #print stuff to thingy if ( $cgi_vars{"data_size"} ) { for ( my $count=0; $count < $cgi_vars{"data_size"}; $count++ ) { print "<!",$data,"->\n"; } } #take time my ( $end_seconds, $end_microseconds ) = gettimeofday; print "End Seconds:$end_seconds End MicroSeconds:$end_microseconds< +BR/>\n"; #compare my $time_delta = ($end_seconds - $start_seconds) + ( ( $end_microsecon +ds - $start_microseconds) / 1000000); if ( $cgi_vars{"data_size"} ) { print "your data transfer of ", $cgi_vars{"data_size"}, "k took ", $ +time_delta, " seconds<BR/>\n"; print "your bandwidth is ",$cgi_vars{"data_size"} / $time_delta ," k +ilobytes/sec<BR/>\n"; my @data = "$time_delta"; my $graph = GD::Graph::hbars->new(400, 300); $graph->set( x_label => 'Transfer Data', y_label => 'Some Label', title => 'Adelphia Speed Test' ); my $gd = my $my_graph->plot(\@data); open(IMG, '>../htdocs/graph.png') or die $!; binmode IMG; print IMG $gd->png; close IMG; } else { print "please invoke as $ENV{'SCRIPT_NAME'}?data_size=100<BR/> \n"; } exit;
Thanks in advanced for all your help!! -Stephen

In reply to GD::Graph Help by sunadmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found