2010年2月7日日曜日

覚書 PERLでのグラフ描画について

画像描画用のモジュールは、GDモジュールを利用。

①CPANより、ダウンロード
GD-2.44.tar.gz

②perl Makefile.PL でエラー

Notice: Type perl Makefile.PL -h for command-line option summary.

**UNRECOVERABLE ERROR**
Could not find gdlib-config in the search path. Please install libgd 2.0.28 or higher.
If you want to try to compile anyway, please rerun this script with the option --ignore_missing_gd.

※libgdっていうライブラリがないくさい

③いまはいってるのは。。。

# rpm -qa | grep gd-
sysklogd-1.4.1-39.2
gd-2.0.33-9.3.fc6

# rpm -qa | grep libgd -> ない
# rpm -qa | grep libp 
libpng-1.2.10-7                  ->これはある
libpcap-0.9.4-8.1

→>ないくさい。

④gd-develをインストールすれば、はいってくるっぽい。
yum install gd-devel
※参考:http://www.libgd.org/FAQ#How_do_I_install_gd_on_Fedora_Linux.3F
※http://www.libgd.orgからおとしてもこれる。

⑤あらためて、GBモジュールのコンパイルを試み。
→エラーなし。

⑥サンプル作成したけど、エラー
GD::Graph::は別途ダウンロードが必要みたい

⑦GDGraph-1.44.tar.gzダウンロード

Checking if your kit is complete...
Looks good
Warning: prerequisite GD::Text 0.80 not found.
Writing Makefile for GD::Graph

The automatic tests for GDGraph are not really a solid workout of the
library. The best way to test the package is to run the examples
before installing it. You can run the examples in the samples
directory with `make samples` or by going into that directory, and
just running `make`.
If that fails, please read samples/Makefile.

※無視したけどやっぱだめ。

⑧GDTextUtil-0.86.tar.gzもいれる

→OK

後で見つけた、結局ここの説明がすべてかも。
http://www.gadgety.net/shin/tips/unix/perl-gd.html
日本語化への対応も記載あり。


⑨サンプル スクリプト
#! /usr/bin/perl -wT

use strict;
use CGI;
use GD::Graph::linespoints;
use CGI::Carp qw(fatalsToBrowser);

my @data;
my $querry;
my $graph;

$querry = new CGI;

@data = (["2/1", "2/2", "2/3", "2/4", "2/5", "2/6", "2/8", "2/9", "2/10", "2/11"],
[99,40,35,49,85, 20, 24,45,30,78, 69],
[1,3,5,7,9,10,11,12,13,14,15]);

$graph = new GD::Graph::linespoints();
binmode STDOUT;

$graph->set(
title => "resouce usage rate",
x_label => "Day",
y_label => "Usage Rate % ",
long_ticks => 1,
y_max_value => 100,
y_min_value => 0,
y_tick_number => 10
);

print $querry->header( - type => "image/png", -expires=>"now");
print $graph->plot(\@data)->png;



⑩画像をリンクとするには
 <img src="/cgi-bin/gdtest.pl" border="0" /> ※<>半角


これでグラフ描画の課題はひとまず終了かなと。

0 件のコメント: