--- loncom/cgi/graph.png 2003/10/29 15:18:09 1.31 +++ loncom/cgi/graph.png 2005/05/25 22:31:51 1.35 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: graph.png,v 1.31 2003/10/29 15:18:09 matthew Exp $ +# $Id: graph.png,v 1.35 2005/05/25 22:31:51 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,7 +59,7 @@ use GD::Graph::bars; use GD::Graph::lines; use GD::Graph::colour; use GD::Graph::Data; -use LONCAPA::loncgi(); +use LONCAPA::loncgi; sub unescape { my $str=shift; @@ -92,8 +92,8 @@ my $id = $ENV{'QUERY_STRING'}; # usage: &get_env($name,$default) sub get_env { my $key = 'cgi.'.$id.'.'.(shift()); - return shift if (! exists($ENV{$key})); - return $ENV{$key}; + return shift if (! exists($Apache::lonnet::env{$key})); + return $Apache::lonnet::env{$key}; } if (! &LONCAPA::loncgi::check_cookie_and_load_env()) { @@ -172,6 +172,9 @@ if ($PlotType eq 'bar') { $GraphSettings{'zero_axis'} = 1; if (&get_env('two_axes',0)) { $GraphSettings{'two_axes'} = 1; + $GraphSettings{'y1_label'} = &get_env('y1_label', + $GraphSettings{'y_label'}); + $GraphSettings{'y2_label'} = &get_env('y2_label',''); $GraphSettings{'y1_max_value'} = &get_env('y1_max_value',0); $GraphSettings{'y1_min_value'} = &get_env('y1_min_value',1); $GraphSettings{'y2_max_value'} = &get_env('y2_max_value',1); @@ -195,11 +198,13 @@ if (! defined($MyGraph)) { ## ## Build the @Data array my $NumSets = &get_env('NumSets'); -my @Data; # stores the data for the graph +my @Data; # stores the data for the graph +my @Legend; # one entry per data set my @xlabels = split(',',&get_env('labels')); push(@Data,\@xlabels); for (my $i=1;$i<=$NumSets;$i++) { push(@Data,[split(',',&get_env('data.'.$i))]); + push(@Legend,&get_env('data.'.$i.'.label',undef)); } my $error = ''; @@ -208,6 +213,11 @@ if (! $MyGraph->set(%GraphSettings)) { return; } +if (join('',@Legend) ne '') { + $MyGraph->set_legend(@Legend); +} + + my $plot = $MyGraph->plot(\@Data); if (! defined($plot)) { my $error = 'Unable to plot the data provided.';