Annotation of loncom/cgi/graph.png, revision 1.1

1.1     ! minaeibi    1: #!/usr/bin/perl
        !             2: #
        !             3: # The LearningOnline Network with CAPA
        !             4: #
        !             5: # Behrouz Minaei
        !             6: # 9/13/2001, 9/25/2001
        !             7: # 10/6/2001, 10,9,2001
        !             8: #
        !             9: # A CGI script that dynamically outputs a graphical chart for lonstatistics.
        !            10: 
        !            11: use strict;
        !            12: use GD::Graph::bars;
        !            13: use GD::Graph::colour;
        !            14: use GD::Graph::Data;
        !            15: 
        !            16: my ($cid, $Tag, $Max, $PNo, $data) = split(/&/,$ENV{'QUERY_STRING'});
        !            17: 
        !            18: my @data1=split(/\,/,$data);
        !            19:    
        !            20: my @xlabels;
        !            21: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
        !            22:     $xlabels[$nIdx]=$nIdx+1;
        !            23: } 
        !            24: my @data =(\@xlabels,\@data1);
        !            25: 
        !            26: #print "Content-type: text/html\n\n";
        !            27: #print $ENV{'QUERY_STRING';
        !            28: #print "<br>";
        !            29: #print $Max;
        !            30: #print "<br>";
        !            31: #print $PNo;
        !            32: #print "<br>";
        !            33: #print $data;
        !            34: #exit;
        !            35: 
        !            36: my $Range;
        !            37: if ( $PNo > 10 ) {$Range = 30*$PNo;}
        !            38: else { $Range = 300+30*$PNo; }
        !            39: 
        !            40: if ( $Max < 1 ) { $Max = 1; }
        !            41: elsif ( $Max < 10 ) { $Max = 10; }
        !            42: elsif ( $Max < 100 ) { $Max = 100; }
        !            43: 
        !            44: my $MyGraph = GD::Graph::bars->new($Range, 400);
        !            45: 
        !            46: $MyGraph->set( 
        !            47:     x_label         => 'Problems #',
        !            48:     y_label         => $Tag,
        !            49:     title           => 'LON-CAPA Graphical Chart, Course: '.$cid,
        !            50:     y_max_value     => $Max,
        !            51:     y_tick_number   => 10,
        !            52:     y_label_skip    => 1,
        !            53:     x_label_skip    => 2,
        !            54:     
        !            55:     # colors
        !            56:     dclrs           => [ qw(green lblue lyellow lpurple cyan lorange)],
        !            57:     
        !            58:     # shadows
        !            59:     bar_spacing     => 4,
        !            60:     shadow_depth    => 1,
        !            61:     shadowclr       => 'dred',
        !            62: 
        !            63:     transparent     => 0,
        !            64: ) or warn $MyGraph->error; 
        !            65: 
        !            66: # Tell the server we are sending a gif graphic
        !            67: print <<END;
        !            68: Content-type: image/gif
        !            69: 
        !            70: END
        !            71: 
        !            72: my $BinaryData=$MyGraph->plot(\@data)->png;
        !            73: undef $MyGraph;
        !            74: binmode(STDOUT);
        !            75: open IMG,"|pngtopnm|ppmtogif"; # convert into a gif image
        !            76: print IMG $BinaryData; # output image
        !            77: $|=1; # be sure to flush before closing
        !            78: close IMG;
        !            79: 
        !            80: 
        !            81: 
        !            82: 
        !            83: 
        !            84: 
        !            85: 
        !            86: 
        !            87: 
        !            88: 
        !            89: 
        !            90: 
        !            91: 
        !            92: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>