#!/usr/bin/perl use strict; use warnings; # running-times 15-05-05 # # Graphing all my running times. # I will just insert the data # directly into this program for now, # but when it becomes too much, Ill # move it into another file/dbm use GD::Graph::linespoints; use Getopt::Std; my %times; # running times my $chart; # the GD::Graph::linespoints object my $plot; # the GD object containing the actual graph my @DAYS = qw(Mon Tue Wed Thu Fri Sat Sun); # process options my %Opt; getopts('ho:', \%Opt); if ($Opt{h} or !$Opt{o}) { die "Usage:\n\t$0 -o outfile.png \n"; } # Running times %times = ( "Mon" => "25.40", "Tue" => "24.20", "Wed" => "22.50", "Thu" => "23.30", "Fri" => "21.10", "Sat" => "24.30", "Sun" => "25.19", ); # build graph $chart = GD::Graph::linespoints->new( 480, 320, 1); $chart->set( x_label => "Day", y_label => "Time (mins)", y_min_value => -26, y_max_value => -20, markers => [ 4 ], show_values => 1, y_number_format => sub{ return abs $_[ 0 ] }, values_format => sub{ return abs $_[ 0 ] }, title => "Running Times for 5km - W/E May 15th 2005" ); $plot = $chart->plot( [ [ @DAYS ], [ map{ -$_ } @times{@DAYS} ], ] ); # save it open(F, "> $Opt{o}") or die "Can't open $Opt{o} for writing: $!\n"; print F $plot->png; close F; # Create html page with png in it open H, ">times.html" or die "Can not create webpage: $!\n"; use CGI; my $query = CGI->new( ); print H $query->start_html(-title=>'Gavins Weekly Running Times'); print H $query->p("Here are your times:"); print H "