Re: [問題] 關於畫圖,GD畫圖

看板Perl作者 (What?)時間14年前 (2010/11/23 22:48), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
你說 @data 的內容如下: @data = ([1,2,3,4,5,6,7],#這是X [10,9,8,7,6,8],#之後都是Y [201,190,180,170,160,155,176], [...]#依此類推。 ); 可以你在程式內 @data 的 assignment 卻是: @data = ([@num], [@file] ); 這樣 @data 將永遠只包含兩個元素,而不是你原本所希望的內容 也許你可以將程式改為: my @file = map { chomp; [ split(/\t/) ] } <FH>; ... @data = ([@num], @file ); 也許這樣才是你所希望的內容... ※ 引述《sqrt1089 (李崩子)》之銘言: : =====以下是程式碼===== : #!/usr/local/bin/perl -w : use CGI ':standard'; : use GD::Graph::lines; : open (FH,"02.txt")||die"File open Error!\n"; : my @file = map { chomp; split(/\t/) } <FH>; : @num=(1..$#file+1);#定義X軸的值 : @data = ([@num], : [@file] : ); : my $mygraph = GD::Graph::lines->new(900, 300); : $mygraph->set( : x_label => 'X', : y_label => 'Y', : title =>'Test', : # Set the thickness of line : line_width => 1, : ) ;#or warn $mygraph->error; : my $myimage = $mygraph->plot(\@data) or die $mygraph->error; : binmode STDOUT; : print $myimage->png; : =================== : 以下是我執行後。 : C:\>perl GD99.pl >test.png : 然後test.png 長這樣 http://ppt.cc/ZIi, : 然後我的記事本的內容是這樣 : 10 9 8 7 6 8 : 201 190 180 170 160 155 176 : 就是2行數。 : 我最後是希望能有2條曲線,可是我再怎麼弄都是一條,而且是全部的值拿去畫 : 如果是要寫死是這樣 : @data = ([1,2,3,4,5,6,7],#這是X : [10,9,8,7,6,8],#之後都是Y : [201,190,180,170,160,155,176], : [...]#依此類推。 : ); : .. : . : 在這先說聲謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.251.162.40

11/24 13:14, , 1F
讚!推推推!! 原來split還要用[ ]框起來
11/24 13:14, 1F
文章代碼(AID): #1CwzGoKD (Perl)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1CwzGoKD (Perl)