Generate gif on the fly (up to 3 sec.) reading the data from a file. The file can be txt, csv etc.
#generate_gif.pl
use strict;
use GIFgraph::bars;
use GD::Graph::colour;
# the rgb.txt and data.data files must be in the same
# directory as the generate_gif.pl is
#
# the data row from data.data file, must begin with a
# tab, else the first element is ignore. :((
GD::Graph::colour::read_rgb("rgb.txt") or
die "Cannot read colours from rgb.txt";
my $data_max;
my @data = read_data_from_file("data.data")
or die "Cannot read data from data.data";
my $my_graph = new GIFgraph::bars(800,600 );
$my_graph->set(
x_label => 'Items',
y_label => 'Data chart',
title => 'Report Data',
y_max_value => $data_max,
y_tick_number => 10,
y_label_skip => 2,
long_ticks => 1,
bar_spacing => 3,
show_values => 1,
legend_marker_width => 24,
dclrs => [ qw( lightsteelblue limegreen blue red spr
+inggreen2 yellowgreen springgreen orange) ],
);
$my_graph->set_legend( 'Data1', 'Data2', 'Data3', 'Data4', 'Data5','Da
+ta6','Data7', 'Data8' );
$my_graph->plot_to_gif( "Chart.gif", \@data );
exit;
sub read_data_from_file
{
my $fn = shift;
my @d = ();
@d=$data_max;
open(FH, $fn) || return ();
while (<FH>)
{
chomp;
my @row = split /\t/;
for (my $i = 0; $i <= $#row; $i++)
{
undef $row[$i] if ($row[$i] eq 'undef');
push @{$d[$i]}, $row[$i];
}
}
close (FH);
return @d;
}