I've been fiddling with GD::Graph and GD::Text all day, but this is eluding me.
GD::Graph is easy enough to use, and I have it producing the graphs I want. But now I would like to add a small table of text at the bottom of the returned PNG graphic, and I can't quite figure that out.
I've tried using the instantiated object as the target of a GD::Text::Wrap operation, but it returns the error "Not a GD::Image object". Puzzling, because the docs clearly say:
$graph->plot(\@data)
Plot the chart, and return the GD::Image object.
So I did this (most of this code is samples from the man pages, I will be using this with real data once I get the output done properly):
#!/usr/bin/perl
use GD::Graph::bars3d;
use GD::Text::Wrap;
my @data = (
[qw (Sun Mon Tue Wed Thu Fri Sat) ],
[ 1100, 1500, 1800, 1950, 2324, 2162, 140],
[ 103, 2000, 1173, 908, 232, 1200, 100],
);
my $graph = new GD::Graph::bars3d( 495, 211 );
$graph->set(
x_label => 'Day of the week',
dclrs => [ qw(red dgreen) ],
bar_spacing => 10,
cumulate => 1,
);
my ($gd) = $graph->plot( \@data )->png;
my $text = <<EOSTR;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
EOSTR
my $wrapbox = GD::Text::Wrap->new( $gd,
line_space => 4,
color => 'black',
text => $text,
);
binmode STDOUT;
print $gd;
..Which returns the error:
Not a GD::Image object at ./graphtest.pl line 26
Any clues? I think I just don't know GD well enough to know the best way to do this. All help appreciated.
"Non sequitur. Your facts are un-coordinated." - Nomad
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.