GD-Graph-Hooks
view release on metacpan or search on metacpan
}
my $graph = GD::Graph::lines->new(1500,500);
$graph->add_hook( 'GD::Graph::Hooks::PRE_DATA' => sub {
my ($gobj, $gd, $left, $right, $top, $bottom, $gdta_x_axis) = @_;
my $clr = $gobj->set_clr(0xaa, 0xaa, 0xaa);
my $x = 10;
while ( $x < $#{ $data[1] }-10 ) {
# compute line endpoints from a datapoint
my @lhs = $gobj->val_to_pixel($x+1, $data[1][$x]);
# to a predicted endpoint, based on the moving average
my @rhs = $gobj->val_to_pixel($x+11, $data[1][$x] + 10*($mv_avg[$x] - $mv_avg[$x-1]));
print "adding line from data point (@lhs) to value predicted by mv_avg (@rhs)\n";
$gd->line(@lhs,@rhs,$clr);
$x += 10;
}
});
examples/example1.pl view on Meta::CPAN
}
my $graph = GD::Graph::lines->new(1500,500);
$graph->add_hook( 'GD::Graph::Hooks::PRE_DATA' => sub {
my ($gobj, $gd, $left, $right, $top, $bottom, $gdta_x_axis) = @_;
my $clr = $gobj->set_clr(0xaa, 0xaa, 0xaa);
my $x = 10;
while ( $x < $#{ $data[1] }-10 ) {
# compute line endpoints from a datapoint
my @lhs = $gobj->val_to_pixel($x+1, $data[1][$x]);
# to a predicted endpoint, based on the moving average
my @rhs = $gobj->val_to_pixel($x+11, $data[1][$x] + 10*($mv_avg[$x] - $mv_avg[$x-1]));
print "adding line from data point (@lhs) to value predicted by mv_avg (@rhs)\n";
$gd->line(@lhs,@rhs,$clr);
$x += 10;
}
});
( run in 0.436 second using v1.01-cache-2.11-cpan-2b1a40005be )