The $data object is:
my $data = GD::Graph:
ata->new();
I need to look at that closer. I almost emailed the author of the GD
module, but I haven't yet. I may just do that now. Thanks!
Here is an example program. It requires a comma seperate file as an
argument with 3 columns of data. Column1 = time, Column2 = Voltage,
Column3 = Current
#!c:/perl/bin/perl.exe
# #!/usr/bin/perl -w
#
# A mixed stock graph
# usese ActiveState Module: GDGraph
use strict;
use GD;
use GD::Graph:
ata;
use GD::Graph::mixed;
use IO::File;
use Getopt::Long; # Perl module used to parse arguments from the
command line.
use File::Basename; # to get the filebase name for creating parsed
data directory
use File::Find; # get all files and and sub-directory files.
# Variable Declaration
my $buffer; # for binary data reading/writing
my $argc; # number of arguments at execution
my $debug; # option flag - used to print diagnostic info
to screen
my $ascfile; # ASCII input file (*.asc)
my $ascDir; # output folder name for parsed data.
my $ascPath; # output directory path to parsed data.
my $fh_output; # array of output file handles for the output
files
my $record_cnt=1;
my $line_cnt;
my $recfile_cnt=1;
my $prev_pct; # Currect completion
my $record; # The current record being processed.
my $file_cnt = 0; # counter of the number of $line_cnt / 30,000
in the file.
my $file_index = 1;
my @my_dirs;
my $inputFile;
my $graph;
my $data = GD::Graph:
ata->new();
my $debug;
my $forcewrite;
my $dataVer;
my $cfg_filename;
my $extractOnly;
#new page
# --------------------------------------------------------
#
# Subroutine: "Main" process - program entry point
#
# --------------------------------------------------------
# special system variable which forces Perl to 'flush' after every
print.
$|=1;
printf(
"\n----------------------------Starting-------------------------------------\n");
printf( "CSV Reporting of Results : test.pl - Version 01.0 December 2,
2005\n");
print "Program started: ", scalar localtime, "\n";
file_verify(); # Open Input File to ensure it exists
die "All arguments must be directories!"
if grep {!-d} @ARGV;
#open MASTER, '>', 'output.cvs';
my $fdir; # output file directory to be created.
@my_dirs = @ARGV;
$fdir = shift @ARGV;
# special system variable which forces Perl to 'flush' after every
print.
$|=1;
parse_directory($ascfile);
print "\nProgram finished: ", scalar localtime, "\n";
printf(
"\n-----------------------------Ending--------------------------------------\n");
# END of Main Process ------------------------------------
sub file_verify {
my $type; #junk
# Input Argument
# -> Input File - ascii input file
$argc = @ARGV; # count the number of input arguments
if ( $argc < 1 ) {
printf( "Usage Model:[perl] csvReport.pl infile.csv [-c|C
config.cfg] [-v1|-v2] [-dD] [-F]\n");
printf( " -> [perl] csvReport.pl \n");
printf( " - perl is the script interpreter. \n");
printf( " - asc2csv.pl is the perl script
(instructions) \n");
printf( " ");
printf( " -> Argument 1 Input file (required) \n" );
printf( " ");
exit;
}
($ascfile) = shift @ARGV;
($ascDir,$ascPath,$type) = fileparse($ascfile, qr{\.csv});
unless (open(ASCFILE, "$ascfile")) {
die "Fatal Error: Cannot open $ascfile for input: $!";
}
}
#
-----------------------------------------------------------------------------
#
-----------------------------------------------------------------------------
# This function will continue until there is no more log files to open.
sub parse_directory {
# next line works.
printf("Opening input file... $ascfile \n"); # debug statement
$graph = new GD::Graph::mixed(900, 600) or die "Can't create graph!";
#parse out the file name.
$data->read(file => $ascfile , delimiter => ',') or die "Couldn't
read data!"; #replaced stock_data.dat
if($ascfile =~ /m220/)
{
graphMsg220($graph);
}
else{}
# Plot the data - generate the plot data
printf("Plotting the data to the graph object \$gd. \n");
my $gd = $graph->plot( $data ) or die "Can't plot graph";
# Write the PNG to a file.
my $outputFile = $ascfile . ".jpg";
printf("Opening output file... $outputFile \n");
open OUT, ">$outputFile" or die "Couldn't open for output: $!";
binmode(OUT);
#print OUT $gd->png();
print OUT $gd->jpeg();
close OUT;
$data->reset();
# close LOG;
# }
}
# END of file_verify Function ----------------------------
#
-----------------------------------------------------------------------------
sub graphMsg220
{
# set the file properties.
# Set the general attributes
$graph->set(
title => " Report - Message 220 - $_",
types => [qw(lines lines)],
dclrs => [qw(red blue)],
transparent => 0,
);
# Set the attributes for the x-axis
$graph->set(
x_label => 'Time (Seconds)', # replaced Day of
Year
x_tick_number => 5,
x_label_skip => 5,
x_labels_vertical => 1,
);
$graph->set(
y_max_value => ($data->get_min_max_y_all())[1]+25,
y_tick_number => 20,
y_all_ticks => 1,
y_number_format => sub { int(shift); }, # '$'.
);
# Set the legend
$graph->set_legend('Voltage', 'Current');
$graph->set_legend_font(gdLargeFont);
$graph->set(legend_placement => 'BL');
}
# END of graphMsg220 Function ---------------------------------