[Graph-dev] Chart::Graph::Gnuplot question - syntax for plotting a hash

Daniel Naughton dan@productengineering.com
Sun, 21 Jul 2002 21:30:39 -0500


This is a multi-part message in MIME format.
--------------2EB2DA60E674875E45E2E1CB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

If you don't mind answering a question for a newcomer to you program, I
was hoping someone there could help me out.  I'm trying to create a
graph from some data stored in a hash.  I can't get the syntax right.
I keep getting "Matrix entry must be a reference to an array at".  I've
manually put the data in that section per the man page, and everything
works fine.  I've checked everywhere I could think of to find an example
of how to pass data to your module, but no luck.  If you could help me
out, I'd appreciate it.  Thanks for whatever help you could offer me.



--------------2EB2DA60E674875E45E2E1CB
Content-Type: application/x-perl;
 name="graph.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="graph.pl"

#!/usr/bin/perl
use Chart::Graph::Gnuplot qw(gnuplot);

%data = qw(
   01/01/2002	11
   02/01/2002	20
   03/01/2002	32
   04/01/2002	38
   05/01/2002	45

);
foreach $value (keys(%data)) {
  print "for date " . $value . ", the total is: " . $data{$value} . "\n";
  $manual_reformat = "[" . '"' . "$value" . '"' . "," . $data{$value} . "]"; 
  push (@graph_data,$manual_reformat);
}
$graph = join(",",@graph_data);
print "we're going to try to graph: " . $graph . "\n";
plot_graph();

sub plot_graph {
      gnuplot({"title" => "test graph",
             "output type" => "png",
             "output file" => "gnuplot1.png",
             "xdata" => "time",
             "timefmt" => "%m/%d/%Y",
             "format" => ["x","%m/%d/%Y"],
             },
             [{"title" => "data1",
               "type"  => "matrix",
               "style" => "lines"}, [
                                      "$graph" ],
             ] );
}

--------------2EB2DA60E674875E45E2E1CB--