Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^5: Keys and Values from Hash

by poj (Monsignor)
on Jul 18, 2014 at 17:35 UTC ( #1094236=note: print w/replies, xml ) Need Help??

in reply to Re^4: Keys and Values from Hash
in thread Keys and Values from Hash

My end goal is to create an HTML page, which will display a Column Chart

In that case, here's a long pass up the field for you ..

#!perl; use strict; use GD; use GD::Graph::bars; # test data my %spend = (); for ('A'..'Z'){ $spend{'Customer_'.$_} = { money9am => int rand(1000), money3pm => int rand(1000) }; }; # graph my $date = scalar localtime; my $graph = GD::Graph::bars->new(800,400); $graph->set( y_label => 'Spend', title => 'Customer spend for '.$date, bar_spacing => 5, cycle_clrs => 1, x_labels_vertical => 1, ) or die $graph->error; $graph->set_x_axis_font(gdMediumBoldFont); $graph->set_y_axis_font(gdMediumBoldFont); # table and graph data my @x=(); my @y=(); my $table = q!<table cellspacing="0" cellpadding="5" border="1">!; for my $cust (sort keys %spend){ my $spend = $spend{$cust}{'money9am'}+$spend{$cust}{'money3pm'}; push @x,$cust; push @y,$spend; $table .= qq!<tr><td>$cust</td><td align="right">$spend</td></tr>!; } $table .= q!</table>!; # plot my $gd = $graph->plot([\@x,\@y]) or die $graph->error; # save chart as gif (my $filename = $date) =~ s/ /_/g; $filename =~ s/://g; open IMG, '>',$filename.'.gif' or die $!; binmode IMG; print IMG $gd->gif; # create html open HTM, '>report.htm' or die $!; print HTM qq(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http: +//"> <head><title>Spend for $date</title></head> <body><h3>Spend for $date</h3> <p><img src="$filename.gif" alt="chart"></p> $table </body></html>);
For more graph options see GDGraph

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1094236]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-06-22 11:28 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.