■sample42.gif
【要点】
(1)折れ線+点グラフを描く
GD::Graph::linespoints;
(2)表示データをファイルから読み込む
@data = read_data_from_csv("sample42.dat") #データセット
or die "Cannot read data from sample42.dat";
・
・
・
sub read_data_from_csv #ファイル(SVC)読み込みルーチン
{
・
・
・
return @d; #返す値は、無名配列であること
}
(3)undef(未定義)データポイントスキップし線を連続させる
skip_undefが未定義。
# 1:undef(未定義)データところは線を連続
#させません。
# 0:undef(未定義)データは飛ばし、線が連続
#します。(デフォルト)
#skip_undef=1の例は、No.21 sample41.gif参照。
|
|
■sample42.pl
chdir("C:\\Inetpub\\wwwroot\\uriage"); #カレントディレクトリ指定(IISの場合)
use lib 'C:/Inetpub/wwwroot/uriage'; #GD::Graphライブラリ格納フォルダ GD (固定)の場所
#
use GD::Graph::linespoints;
require 'save.pl';
print STDERR "Processing sample42\n";
@data = read_data_from_csv("sample42.dat")
or die "Cannot read data from sample42.dat";
$my_graph = new GD::Graph::linespoints( );
$my_graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Lines and Points Graph, reading a CSV file',
y_max_value => 80,
y_tick_number => 6,
y_label_skip => 2,
markers => [ 1, 5 ],
transparent => 0,
);
$my_graph->set_legend( 'data set 1', 'data set 2' );
$my_graph->plot(\@data);
save_chart($my_graph, 'sample42');
sub read_data_from_csv
{
my $fn = shift;
my @d = ();
open(ZZZ, $fn) || return ();
while ()
{
chomp;
# you might want Text::CSV here
my @row = split /,/;
for (my $i = 0; $i <= $#row; $i++)
{
undef $row[$i] if ($row[$i] eq 'undef');
push @{$d[$i]}, $row[$i];
}
}
close (ZZZ);
return @d;
}
(参考)
●本ソースコードの1〜3行目(挿入)
1 chdir("C:\Inetpub\wwwroot\uriage"); #カレントディレクトリ指定(IISの場合)
2 use lib 'C:/Inetpub/wwwroot/uriage'; #GD::Graphライブラリ格納フォルダ GD (固定)の場所
3 #
Windows IIS 走行用に元ソースに挿入
●>save.pl(グラフ画像保存ルーチン)
●>Sample42.dat(グラフデータファイル)
|