Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

GD::Graph legend only shows 1 entry

by bageler (Hermit)
on Oct 28, 2005 at 21:55 UTC ( #503785=perlquestion: print w/replies, xml ) Need Help??

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

I have a GD::Graph::hbars with X data points. The graph is generated properly, however I cannot get the legend to display more than one entry. Any ideas? Here's all the relevant code.
my (@data,$totalvotes,@legend,$i); while (my @r = $sth->fetchrow) { push @{$data[0]}, ++$i; push @legend,"$i: $r[1]"; push @{$data[1]}, $r[2]; $totalvotes += $r[2]; } $sth->finish; if ($totalvotes > 0) { for (@{$data[1]}) { $_ = int(($_ / $totalvotes) * 100).'%'; } }
my $graph = GD::Graph::hbars->new(300,70*$#{$data[0]}); $graph->set ( y_label => 'Vote Percentage', x_label => 'Responses', title => $self->{poll}->{question}, y_max_value => 100, y_tick_number => 10, bar_spacing => 6, show_values => 1, dclrs => [ qw(lgreen orange cyan lred) ], cycle_clrs => 1, legend_placement => 'BL', legend_marker_height => 12, ) or warn $graph->error; $graph->set_legend(@legend); my $gd = $graph->plot(\@data) or warn $graph->error;

Replies are listed 'Best First'.
Re: GD::Graph legend only shows 1 entry
by randyk (Parson) on Oct 29, 2005 at 15:06 UTC
    The problem may have something to do with the structure of your data. Does the following example work for you in displaying all 3 values for the legend?
    use GD::Graph::hbars; use strict; use warnings; my @data = ( ['Jan', 'Feb', 'Mar', 'Apr'], [5, 7, 9, 6], [2, 2, 3, 1], [4, 4, 6, 3], ); my @legend = qw(maximum minimum average); my $graph = GD::Graph::hbars->new(600, 500); $graph->set ( x_label => 'Month', y_label => 'Value', title => 'GD::Graph::hbars example', bar_spacing => 6, show_values => 1, legend_placement => 'BL', legend_spacing => 5, show_values => 1, legend_marker_height => 12, dclrs => [ qw(orange cyan lred) ], ) or warn $graph->error; $graph->set_legend(@legend); my $gd = $graph->plot(\@data) or warn $graph->error; open(IMG, ">graph.png") or die $!; binmode IMG; print IMG $gd->png; close IMG;
      It does not work. I tried many ways of setting the legend:
      @legend = (1,2,3); $graph->set_legend(@legend); $graph->set_legend(qw(foo bar baz)); $graph->set_legend('foo','bar','baz');
      none of the above worked.
        What version of GD::Graph are you using? The example I gave worked for me with GD::Graph version 1.43, and GD version 2.30 (on Win32 ActiveState perl-5.8.7).
Re: GD::Graph legend only shows 1 entry
by jesuashok (Curate) on Oct 29, 2005 at 10:02 UTC
    Hi,

    There are lot questions posted on GD::Graph in recent days. Please go throught that one. Please post your understandings and obstacles you faced in Monks Discussion It will be very useful for the people who are Yet to start GD::Graph

    "Keep pouring your ideas"
      If I saw a thread that was relevant, I would have posted there. I'm no stranger around here, such as your status describes yourself, and if I did see anything useful I would add a meditation. Monks discussion is talk about this site itself, not about general perl problems.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://503785]
Approved by socketdave
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2022-10-05 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (24 votes). Check out past polls.

    Notices?