[rrd-users] Problems graphing
Laura McCord
mccordl at southwestern.edu
Fri Sep 26 17:05:21 CEST 2008
I have my data loaded into an array but everytime I try to graph the
data I get a "Can't call method "png" on an undefined value...
I am using Perl and the Graph module to produce a bar graph. Here is a
sample of my data and my source code. Perhaps someone will notice what I
am doing wrong.
Thanks.
Here is some sample data:
Fri Sep 26 00:00:00 2008 0.1
Fri Sep 26 01:00:00 2008 0.0
Fri Sep 26 02:00:00 2008 0.1
Fri Sep 26 03:00:00 2008 0.1
Fri Sep 26 04:00:00 2008 0.2
Fri Sep 26 05:00:00 2008 0.1
Fri Sep 26 06:00:00 2008 0.2
Fri Sep 26 07:00:00 2008 0.1
Fri Sep 26 08:00:00 2008 0.2
Fri Sep 26 09:00:00 2008 0.2
Fri Sep 26 10:00:00 2008 0.2
Here is a snippet of code:
#Every Hour
my $res = '60';
# Start on Sep 1st
my $start_t = "1220227200";
my $start_t_res = int($start_t/$res)*$res;
#End on Today's Date
my $end_t = "(int($start_t/$res)*$res)";
my ($start,$step,$names,$data) =
RRDs::fetch("stats.rrd","AVERAGE","-r","$res","-s",
"$start_t_res","-e","now");
print "Start: ", scalar localtime($start), " ($start)\n";
print "Step size: $step seconds\n";
print "DS names: ", join (", ", @$names)."\n";
print "Data points: ", $#$data + 1, "\n";
print "Data:\n";
foreach my $line (@$data) {
$start += $step;
$min++;
#Here I am only loading hourly data into the array
if($min == 60){
$array1[$i] = localtime($start);
foreach my $val (@$line) {
$array2[$i] = $val;
}
$i++;
$min=0;
}
}
for($i=0;$i < @array1; $i++){
print $array1[$i]." ";
printf "%12.1f ", $array2[$i];
print "\n";
}
@actualdata = (\@array1,\@array2);
my $graph = new GD::Graph::bars;
$graph->set(
x_label => 'Date/Time',
y_label => 'Messages',
title => 'Dropped Messages',
y_max_value => 10,
y_tick_number => 1,
y_label_skip => 1,
# shadows
bar_spacing => 10,
shadow_depth => 4,
shadowclr => 'dred',
transparent => 0,
) or warn $graph->error;
my $image = $graph->plot(\@actualdata)->png();
More information about the rrd-users
mailing list