Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^5: Keys and Values from Hash

by poj (Priest)
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: +//www.w3.org/TR/html4/strict.dtd"> <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
poj


Comment on Re^5: Keys and Values from Hash
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2015-07-04 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls