http://www.perlmonks.org?node_id=495713

bar10der has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am trying to create a barchart to display progress of various open projects. Progress data is stored in database.

I am able to extract data from database and plot the graph but if i try to set legends through a variable, my script fails. Here is the code:-

$sql="SELECT pno,pname FROM t1 WHERE status=? AND ctry=?"; my $sth = $dbh->prepare($sql); $sth->execute('O','GB'); while(my $row=$sth->fetchrow_hashref){ push @projects,$row; } ##Now get progress data from table $sql="SELECT NVL(progress,0) FROM chart WHERE pno=? AND chartyear = 20 +05 AND chartmonth in(6,7,8) ORDER BY chartmonth"; foreach (@projects){ $pno= $_->{'PROJECTNUMBER'}; @dat=getMultiRows($sql,1,$dbh,$pno); push(@data,\@dat); $projectname .= "'".$_->{'PROJECTNAME'}."'".","; } chop $projectname; ##Now plot the graph my $mygraph = GD::Graph::bars->new(500, 300); $mygraph->set( x_label => 'Months', y_label => '% Completed', title => 'Project Log progress', bar_width => 2, bar_spacing => 2, long_ticks => 1, show_values => 1, x_label_position => 0.5, t_margin => 10, b_margin => 10, l_margin => 10, r_margin => 10, ) or warn $mygraph->error; $mygraph->set_legend_font(GD::gdMediumBoldFont); $mygraph->set_legend('Dynamic reconfiguration FY06 Initiative','Rmg Es +calation Management Tool'); # Works fine ##Above works but when I try following it fails though value of $proje +ctname is same as above value supplied to set_legend function. #$mygraph->set_legend($projectname); #This fails my $myimage = $mygraph->plot(\@data) or die $mygraph->error; print "Content-type: image/png\n\n"; print $myimage->png;
Can someone help me please?

Thanks for your help