Sparklines are something that I haven't seen mentioned on perlmonks so far. Sparklines are small graphs that are base64 encoded and embededded into plain html (see: http://www.ietf.org/rfc/rfc2397.txt for further details). There is already a module on cpan: GD::Graph::sparklines to build line-graphs as sparklines. My snippet is just a quick hack to show a way to build different kind of sparklines using GD and MIME::Base64 :
#!/usr/bin/perl
use strict;
use warnings;
use GD::Graph;
use GD::Graph::pie;
use MIME::Base64;
my @data = (
["1st","2nd"],
[ 1, 2],
);
my $graph = new GD::Graph::pie( 120, 120 );
$graph->set( dclrs => [ qw( #FECECE #FEFECE #FFFFFF ) ],
start_angle => 90 );
my $gd = $graph->plot(\@data) or die $graph->error;
print '<IMG SRC="data:image/png;base64,',
encode_base64($gd->png),
'" alt="sparkline"/>';
In reply to sparklines
by neniro
-
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.
|