#!/usr/bin/perl -w 
use CGI qw/:standard/; # load standard CGI routines 
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use GD; 
# GD module 
use GD::Graph::bars; 
# use for bar graph 
use GD::Graph::lines; 
# use for line graph 
use GD::Graph::linespoints; 
# use for line graph with data points marked 
use GD::Graph::points; # use for points on graph 
use GD::Graph::mixed; 
# use for mixing types, lines and bars for example 
use GD::Graph::colour; # use for colors of text and graph elements 
use GD::Text; 
# use for text fonts 
# data stored for use in plotting bars, lines, points, mixed where 
# first line is x axis labels (assumed to be equally spaced along x 
# axis) 
# remaining lines are individual data sets of y values corresponding 
# to x axis labels 
@datareg = ( 
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], 
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], 
[ 2, 6, 3, 1.5, 4, 1, 5, 3, 1] 
); 
# data stored for use with lines, points where x values are numeric and 
# not equally 
# spaced (using x_tick_number => 'auto') 
# first line is numeric x values 
# remaining lines are individual data sets of y values corresponding to 
# x values 
@dataxtn = ( 
[1, 1.5, 1.7, 2, 3, 5, 5,1, 6, 8], 
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], 
[ 2, 6, 3, 1.5, 4, 1, 5, 3, 1] 
); 
my $my_graph = GD::Graph::points->new(400, 300); 
$my_graph->set_title_font(gdGiantFont); 
$my_graph->set( 
bgclr => 'white', 
fgclr => 'dbrown', 
dclrs => ['black'], 
transparent => 0, 
x_label => 'MY X Label', 
x_label_position =>.2, 
y1_label => 'Y1 label', 
y2_label => 'Y2 lablel', 
two_axes =>1, 
x_ticks =>1, 
x_long_ticks =>1, 
y_tick_length => -3, 
x_label_skip => 2, 
x_labels_vertical =>1, 
title => 'Some simple graph', 
y_max_value => 8, 
y_min_value => 0, 
y_tick_number => 8, 
y_label_skip => 2, 
line_types =>[1,3], 
line_width => 2, 
markers => [1,7], 
marker_size => 2, 
bar_spacing => 2, 
bar_width => 10, 
show_values => 1, 
types => ['lines','bars'] 
) or die $my_graph->error; 
#********************************************************* 
# comment out next line for numeric x values not equally spaced 
#my $gd = $my_graph->plot(\@datareg) or die $my_graph->error; 
# uncomment next two lines for numeric x values not equally spaced 
$my_graph->set( x_tick_number => 'auto') ; 
my $gd = $my_graph->plot(\@dataxtn) or die $my_graph->error; 
#********************************************************* 
# the following retrieves hotspots for all elements of dataset 1 
@hotspot=$my_graph->get_hotspot(1); 
#open a file for writing; note the address used here 
$base = "/var/www/images/"; 
$graph_file = $base."graph.png"; 
open(IMG, ">$graph_file") or die $!; 
binmode IMG; 
print IMG $gd->png; 
close IMG; 
# create the CGI object and send image 
$q = new CGI; 
print 
$q->header('text/html'), 
$q->start_html, 
$q->h1('Graph Test'), 
#note path here is different from path to save file; this is because the way the server is 
#set up, bioed.bu.edu starts at /usr/local/apache2/www 
#this will be different on different systems 
#*********************************************************** 
# the following displays the image on the web page; uses an image 
# map to make the image clickable; uses alt tags to make a pop-up 
# text over parts of the image 
$q->img 
({-src=>'http://192.168.3.253/images/graph.png', 
-usemap=>'#imageMap1', 
-alt=>'graph with image map'}), 
'<MAP NAME="imageMap1">', 
'<AREA SHAPE="RECT" COORDS="50, 50, 150, 150" HREF="http://192.168.3.253" 
alt = "lbi homepage">', 
'</MAP>'; 
#********************************************************* 
# print the hotspots for all the elements in dataset 1. 
for $aref ( @hotspot) { 
print "<P> [ @$aref ],\n"; 
} 
print 
"<p>hotspot 1 = @hotspot <br>", 
$q->end_html;
