Annotation of loncom/cgi/graph.png, revision 1.4
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;
1.3 minaeibi 12: use GD::Graph::bars3d;
1.1 minaeibi 13: use GD::Graph::colour;
14: use GD::Graph::Data;
15:
1.4 ! matthew 16: $|=1; # Autoflush after each print/write
1.1 minaeibi 17: my ($cid, $Tag, $Max, $PNo, $data) = split(/&/,$ENV{'QUERY_STRING'});
18:
19: my @data1=split(/\,/,$data);
20:
21: my @xlabels;
22: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
23: $xlabels[$nIdx]=$nIdx+1;
24: }
25: my @data =(\@xlabels,\@data1);
26:
27: my $Range;
28: if ( $PNo > 10 ) {$Range = 30*$PNo;}
29: else { $Range = 300+30*$PNo; }
30:
1.3 minaeibi 31: if ( $Max <= 1 ) { $Max = 1; }
32: elsif ( $Max <= 10 ) { $Max = 10; }
33: elsif ( $Max >= 60 ) { $Max = 100; }
1.1 minaeibi 34:
1.3 minaeibi 35: my $MyGraph = GD::Graph::bars3d->new($Range, 400);
1.1 minaeibi 36:
37: $MyGraph->set(
38: x_label => 'Problems #',
39: y_label => $Tag,
40: title => 'LON-CAPA Graphical Chart, Course: '.$cid,
41: y_max_value => $Max,
42: y_tick_number => 10,
43: y_label_skip => 1,
44: x_label_skip => 2,
45:
46: # colors
1.3 minaeibi 47: dclrs => [ qw( green lblue lyellow lpurple cyan lorange)],
1.1 minaeibi 48:
49: # shadows
50: bar_spacing => 4,
51: shadow_depth => 1,
52: shadowclr => 'dred',
53:
54: transparent => 0,
55: ) or warn $MyGraph->error;
56:
57: # Tell the server we are sending a gif graphic
58: print <<END;
59: Content-type: image/gif
60:
61: END
62:
63: my $BinaryData=$MyGraph->plot(\@data)->png;
64: undef $MyGraph;
65: binmode(STDOUT);
1.2 minaeibi 66: open IMG,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into a gif image
1.1 minaeibi 67: print IMG $BinaryData; # output image
68: $|=1; # be sure to flush before closing
69: close IMG;
1.3 minaeibi 70:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>