1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
27 our @ISA = qw/Exporter/;
29 our @EXPORT = qw/graphFromQuery/;
32 my ($x,$y,$settings,$query,) = @_;
34 my %graph_settings = (
36 y_number_format => sub { prettyValue abs $_[0]},
37 legend_placement => 'BL',
41 axislabelclr => 'black',
44 my $fields = $query->{NUM_OF_FIELDS};
46 for (my $i = 0; $i < $fields; $i++){
49 while (my @result = $query->fetchrow){
50 for (my $i = 0; $i < $fields; $i++){
51 push @{$fields[$i]},$result[$i];
55 $graph_settings{x_label_skip} = int(1+(scalar @{$fields[0]}) / 6);
57 my $graph = GD::Graph::lines->new($x,$y);
58 $graph->set_legend(@{$query->{NAME}}[1..$fields]) or die $graph->error;
60 for my $key (keys %{$settings}){
61 $graph_settings{$key} = $settings->{$key};
64 $graph->set(%graph_settings);
65 my $gd = $graph->plot(\@fields) or die $graph->error;