use GD; use GD::Graph; use GD::Graph::lines; use GD::Graph::pie; use GD::Graph::bars; use GD::Graph::colour; $field = $inputs{"field"}; $query = "SELECT $field FROM system_info"; print "Query performed: $query

"; ## BEGIN DB ACCESS ## # Make a database handle $dbh = DBI->connect('dbi:Oracle:server', 'username', 'pass',) || die "Database connection not made $DBI::errstr"; # Make a statement handle $sth = $dbh->prepare($query); $sth->execute; $i=0; while (@data=$sth->fetchrow_array()) { @array[$i]=$data[0]; $i++; } # Sort the array @array = sort {$a cmp $b} @array; $a=0; $b=0; $array_length = scalar(@array); print "Generating a graph for $array_length machines. Please wait..."; # Create an associative array for all entries and the number of times in database while ($a < $array_length) { $b = $a + 1; if ($array[$a] =~ $array[$b]) { $count{$array[$a]}++; } $a++; } #### Start Graph Stuff @keys = keys(%count); @values = values(%count); @graphdata = ([@keys],[@values]); $num_graph_columns = scalar (@keys); $width=$num_graph_columns * 30; if ($width < 450) { $width=450; } $graph = GD::Graph::bars->new($width, 500); $graph->set( x_label => "$field", y_label => "number", title => "Graph of $field", bar_spacing => 6, shadow_depth => 4, shadowclr => 'dred', transparent => '1', x_labels_vertical => '1', show_values => '1' ); $graph->set_title_font('C:/winnt/fonts/arial.ttf', 18); $graph->set_x_axis_font('C:/winnt/fonts/arial.ttf', 8); $graph->set_y_axis_font('C:/winnt/fonts/arial.ttf', 8); $graph->set_y_label_font('C:/winnt/fonts/arial.ttf', 12); $graph->set_x_label_font('C:/winnt/fonts/arial.ttf', 12); $graph->plot(\@graphdata); open(OUTPUT, ">../wwwroot/chart.jpg") or die "Can't open chart.jpg: $!\n"; binmode OUTPUT; print OUTPUT $graph->gd->jpeg(); close(OUTPUT); print "




"; foreach (keys(%count)) { print ""; } print "
$_$count{$_}
";