Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re^5: Keys and Values from Hash by poj
in thread Keys and Values from Hash by David92

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 examining the Monastery: (4)
As of 2024-04-25 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found