Annotation of loncom/cgi/graph.png, revision 1.17
1.1 minaeibi 1: #!/usr/bin/perl
2: #
1.17 ! minaeibi 3: # $Id: graph.png,v 1.16 2002/12/13 21:33:30 albertel Exp $
1.5 minaeibi 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/cgi-bin/graph.gif
24: #
25: # http://www.lon-capa.org/
26: #
1.1 minaeibi 27: # The LearningOnline Network with CAPA
28: # Behrouz Minaei
1.5 minaeibi 29: # YEAR=2001
1.9 minaeibi 30: # 9/13/01, 9/25/01, 10/6/01, 10/9/01, 12/25/01
31: # YEAR=2002
1.13 minaeibi 32: # 2/1/, 5/13, 5/15
1.17 ! minaeibi 33: # YEAR=2003
! 34: # 1/7/
1.1 minaeibi 35: # A CGI script that dynamically outputs a graphical chart for lonstatistics.
1.5 minaeibi 36: #
37: ####
1.1 minaeibi 38:
39: use strict;
1.9 minaeibi 40: use GD::Graph::bars;
1.1 minaeibi 41: use GD::Graph::colour;
42: use GD::Graph::Data;
43:
1.4 matthew 44: $|=1; # Autoflush after each print/write
1.11 minaeibi 45: my ($Titr,$xlab,$ylab,$Max,$PNo,$data1,$data2)=split(/&/,$ENV{'QUERY_STRING'});
46:
47: my @data11=split(/\,/,$data1);
48: my @data12=split(/\,/,$data2);
1.1 minaeibi 49:
50: my @xlabels;
1.17 ! minaeibi 51:
! 52: if ($xlab=~/^Percentage$/){
! 53: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
! 54: $xlabels[$nIdx]=$data11[$nIdx];
! 55: }
! 56: @data11=();
! 57: @data11=split(/\,/,$data2);
! 58: @data12=();
! 59: } else {
! 60: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
! 61: $xlabels[$nIdx]=$nIdx+1;
! 62: }
1.1 minaeibi 63: }
1.11 minaeibi 64:
65: my @data =(\@xlabels,\@data11,\@data12);
1.1 minaeibi 66:
1.12 minaeibi 67: my $Range1;
68: my $Range2;
69:
1.11 minaeibi 70: if ($xlab=~/^Concepts$/){
1.12 minaeibi 71: $Range1=270;
72: $Range2=200;
1.17 ! minaeibi 73: } elsif ($xlab=~/^Percentage$/){
! 74: $Range1=250+20*$PNo;
! 75: $Range2=200;
1.12 minaeibi 76: } else {
1.17 ! minaeibi 77: $Range1=450;
! 78: $Range2=200;
1.11 minaeibi 79: }
1.1 minaeibi 80:
81:
1.12 minaeibi 82: my $MyGraph = GD::Graph::bars->new($Range1,$Range2);
1.1 minaeibi 83:
84: $MyGraph->set(
1.14 minaeibi 85: x_label => $xlab,
1.11 minaeibi 86: y_label => $ylab,
87: long_ticks => 1,
88: tick_length => 0,
89: x_ticks => 0,
90: title => $Titr,
1.1 minaeibi 91: y_max_value => $Max,
1.11 minaeibi 92: # y_tick_number => $ytic,
93: y_label_skip => 1,
94:
1.13 minaeibi 95: dclrs => [ qw( lgreen dgreen lyellow lpurple cyan lorange)],
1.1 minaeibi 96:
1.11 minaeibi 97: bar_spacing => 10,
98: cumulate => 2,
99: zero_axis => 1,
100:
101: # legend_placement => 'RT',
102:
103: fgclr => 'black',
1.13 minaeibi 104: boxclr => 'white',
1.11 minaeibi 105: accentclr => 'dblue',
106: valuesclr => '#ffff77',
107: l_margin => 10,
108: b_margin => 10,
109: r_margin => 10,
110: t_margin => 10,
1.1 minaeibi 111:
112: transparent => 0,
113: ) or warn $MyGraph->error;
1.14 minaeibi 114:
1.12 minaeibi 115:
1.16 albertel 116: # Tell the server we are sending a png graphic
1.1 minaeibi 117: print <<END;
1.16 albertel 118: Content-type: image/png
1.1 minaeibi 119:
120: END
121:
122: my $BinaryData=$MyGraph->plot(\@data)->png;
123: undef $MyGraph;
124: binmode(STDOUT);
1.16 albertel 125: #open IMG,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into a gif image
126: #print IMG $BinaryData; # output image
127: #$|=1; # be sure to flush before closing
128: #close IMG;
129: print $BinaryData;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>