Dear monks,
I'm having problems printing graphs to a web-page from my cgi script. I'm creating the graphs with GD::Graph but when they are displayed on the web I get a load of gibberish like this:
KH*՚@fr'HxA&%4ڃp!7)*R9a
Can anyone tell me whats wrong with the script? The graph is created and printed to file.gif, but is not displayed on my cgi webpage.
Thanks!
@data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4]
);
+
my $graph = GD::Graph::points->new(400, 300);
+
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Some simple graph',
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2
) or die $my_graph->error;
+
+
my $gd = $graph->plot(\@data) or die $my_graph->error;
open(IMG, '>file.gif') or die $!;
binmode IMG;
print IMG $gd->png;
close IMG;
binmode STDOUT;
print $gd->png;
-
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.