ねもぷらす

ふぁいんでぃんぐねもの日記。プログラミングとか育児とか

GD で遊ぶ

GD はインストールが少々めんどくせぇだけで、入ってしまえば使い方はいろいろありそう☆
ちなみにサンプルで CGI を読んでるのは、ヘッダーで'image/png'を出力したかったから。スッとコーディング出来ないorz

#!/usr/bin/perl -w

use strict;

use GD::Graph::lines;
use CGI;

my $cgi = new CGI;

print $cgi->header( -type    => 'image/png',
                    -charset => 'euc-jp' );

eval{
  my $data = [
               [1900, 1910, 1920],
               [  10,   20,   15],
               [  50,   40,   35],
             ];

  my $chart = GD::Graph::lines->new(480,320);
     $chart->set( title   => 'Graph Sample',
                  x_label => 'x test',
                  y_label => 'y test',
                );

  my $plot = $chart->plot( $data ) or die $chart->error;
  my $png_data = $plot->png;

  print $png_data;

};if($@){
  print "Error:$@\n";
}