in reply to GD::Graph set_legend problem

It sounds like you are trying to plot twice. Does this example help?
#!/usr/bin/perl use warnings; use strict; use GD; use GD::Graph::lines; my @data = ( [1, 2, 3, 4, 5, 6, 7, 8, 9,], [ 8, 8.25, 8.5, 8.35, 8.76, 8.21, 8.6, 8.8, 8.5], [ 57.4, 57.6, 57.8, 57.9, 57.4, 58.5, 57, 57.87, 58.34] ); my $my_graph = new GD::Graph::lines (600, 400); $my_graph->set( title => "My Graph", transparent => '0', bgclr => 'lgray', boxclr => 'white', fgclr => 'white', title => 'Some simple graph', x_label => 'X axis label', y1_label => 'Y1 axis label', y2_label => 'Y2 axis label', #boxclr => '#C0C0C0', two_axes => 1, ); $my_graph->set_legend("data set 1", "data set 2"); my $gd = $my_graph->plot(\@data) or die $my_graph->error; open(IMG, ">$0.png") or die $!; binmode IMG; print IMG $gd->png; close IMG;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: GD::Graph set_legend problem
by yelekeri (Novice) on Jul 19, 2006 at 17:14 UTC

    I think you are right, there is two "plot"s, but I never noticed till I add set_legend, take a look at this code.

    #!D:\\tools\\Perl\\bin\\perl.exe use CGI; use GD::Graph::Data; use GD::Graph::bars; use GD; $q = new CGI; my $data = GD::Graph::Data->new(); @data = ( [qw(Env)], [12] , [4]); # And we quickly need to do some manipulations on that my $data = GD::Graph::Data->new(); $data->copy_from(\@data); my $chart = GD::Graph::bars->new(); $chart->set_x_axis_font(gdMediumBoldFont); # to display environment $chart->set_y_axis_font(gdMediumBoldFont); $chart->set_title_font(gdGiantFont); $chart->set_x_label_font(gdGiantFont); $chart->set_y_label_font(gdGiantFont); $chart->set(x_label => "Environment" , y_label => "count", title => "Migration count per environment", bar_spacing => 20, shadow_depth => 5, long_ticks => 0, # this is for horizontal and vertical line +s, dclrs => [qw (lgreen lblue lred)], show_values => 1 ); $chart->set_legend_font(GD::gdMediumBoldFont); $chart->set_legend("ACPT","PROD"); ################### This is the code I just commented ### ### but even with this it was drawing only once. # my $gd = $chart->plot($data); print $q->header('image/png'); binmode STDOUT; print STDOUT $chart->plot(\@data)->png;

    Edited by planetscape - added code tags