2014-02-25 5 views
-1

나는 다음과 같은 코드가 있습니다배열 요소에서 메서드를 호출 할 수 있습니까?

Can't call method "add_series" on an undefined value 

이유 : 나는 그것을 실행하면

my $workbook = Excel::Writer::XLSX->new('a_simple.xlsx'); 
my $worksheet = $workbook->add_worksheet(); 
my @chart_performance1 = $workbook->add_chart(type => 'column', embedded => 1); 
my $no_of_titles = 3; 

for (my $no_of = 0; $no_of < $no_of_titles; $no_of++) { 
    $chart_performance1[ $no_of ]->add_series(
     name  => $chart_heading[ 0 ], 
     categories => [ 'Sheet1', $array_game_titles[ $no_of ] , $row_range_max , 0, 0 ], 
     values  => [ 'Sheet1', $array_game_titles[ $no_of ] , $row_range_max , 1, 1 ], 
    ); 
} 

, 내가 오류를?

+3

무엇이 당신 질문입니까? – ThisSuitIsBlackNot

+0

우리는이 방식으로 모듈 함수 "add_series"를 호출 할 수 있습니다. – LohitRaj

+0

@LohitRaj 시도했을 때 어떻게됩니까? 많은 예제가있는 문서를 읽으십시오. –

답변

0

내 대답 만 대신 배열을 선언 할 필요가있어를 동일한 인스턴스에서 add_chart 메소드를 사용하여 "chart_performance"배열을 선언하고 정의합니다. add_chart 메서드가 하나의 객체를 반환하기 때문에 오류가 발생했습니다. 도움 BTW 주셔서 감사합니다.

my $workbook = Excel::Writer::XLSX->new('a_simple.xlsx'); 
my $worksheet = $workbook->add_worksheet(); 
my @chart_performance; 
my $no_of_titles = 3; 

for (my $no_of = 0; $no_of < $no_of_titles; $no_of++) { 
    $chart_performance[ $no_of ] = $workbook->add_chart(type => 'column', embedded => 1); 
    $chart_performance[ $no_of ]->add_series(
     name  => $chart_heading[ 0 ], 
     categories => [ 'Sheet1', $array_row[ $no_of ], $array_col[ $no_of ], 0, 0 ], 
     values  => [ 'Sheet1', $array_row[ $no_of ], $array_col[ $no_of ], 1, 1 ], 
    ); 
} 
3

이 줄

my @chart_performance1 = $workbook->add_chart(type => 'column', embedded => 1); 

잘못 보인다. add_chart 메서드는 하나의 Excel::Writer::XLSX::Chart 개체를 반환하므로 결과는 일반적으로 배열이 아닌 스칼라에 할당됩니다. 그것은 당신이 요구하는지 불분명하지만 데이터의 세 가지 계열을 나타내는 하나 개의 차트를 만들려고하는 경우에, 당신은 더 같은 것을 원하는 :

my $chart = $workbook->add_chart(type => 'column', embedded => 1); 
... 
for (my $no_of = 0; $no_of < $no_of_titles; $no_of++) { 
    $chart->add_series(...); 
} 
+0

다른 배열에 차트 개체를 할당하려고했는데 다른 제목의 3 가지 데이터 계열에 대해 다른 차트를 얻으려고했습니다. . – LohitRaj

관련 문제