Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Chart::Graph::Gnuplot Array Issue

by vbrtrmn (Pilgrim)
on Jul 21, 2004 at 21:22 UTC ( [id://376385]=perlquestion: print w/replies, xml ) Need Help??

vbrtrmn has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I'm a bit rusty with Perl, I took a hiatus to learn TCL. I'm having an issue with Chart::Graph::Gnuplot, today. Using the General Example from CPAN, I always seem to return an error message, I'm fairly certain that I'm passing the data set as an array, though I may be smoking the crack.. Error:
Data set must be an array at gnuplot.cgi line 9
General Example
use Chart::Graph::Gnuplot qw(gnuplot); gnuplot({"title" => "foo", "x2-axis label" => "bar", "logscale x2" => "1", "logscale y" => "1", "output type" => "png", "output file" => "gnuplot1.png", "xtics" => [ ["small\\nfoo", 10], ["medium\\nfoo", 20], ["l +arge\\nfoo", 30] ], "ytics" => [10,20,30,40,50]}, "xdata" => "time", "format" => ["x", "%m/%d"], "timefmt"=> $date_format, "extra_opts" => "set key left top Left", [{"title" => "data1", "type" => "matrix"}, [[1, 10], [2, 20], [3, 30]] ], [{"title" => "data2", "style" => "lines", "type" => "columns"}, [8, 26, 50, 60, 70], [5, 28, 50, 60, 70] ], [{"title" => "data3", "style" => "lines", "type" => "file"}, "samplefile"],);
Any help is apreciated!

--
paul

Replies are listed 'Best First'.
Re: Chart::Graph::Gnuplot Array Issue
by naChoZ (Curate) on Jul 21, 2004 at 23:11 UTC

    You can do it without necessarily bothering with that module. Abigail-II told me how he does it, so here's a snippet I wrote.

    # {{{ ->create graph method # sub create_graph { my $class = shift; open my $plot => "| /usr/local/bin/gnuplot" or die "Failed to open pipe: $!\n"; my $outfile = "/tmp/graph.png"; print $plot <<" --"; set terminal png color set out "$outfile" set format x "/%b%y/" set xdata time set key left top Left reverse samplen 2 title "Legend" box set timefmt "%s:" set grid xtics ytics set xtics nomirror set ytics nomirror set y3tics nomirror set autoscale set ylabel "ResponseTime" plot "$_[0]" using 1:2 smooth unique axis x1y1 title "Time in +ms" -- #set timefmt "%Y-%m-%d:" close $plot or die "Failed to close pipe: $!\n"; chmod 0644 => $outfile or die "Failed to chmod $outfile: $!\n" +; } # }}}
    I just pass it a filename (which I had previously created with File::Temp). My::Class->create_graph( $filename );

    --
    "A long habit of not thinking a thing wrong, gives it a superficial appearance of being right." -- Thomas Paine
    naChoZ

      DUDE, YOU ROCK! Thanks a lot!

      --
      paul

Re: Chart::Graph::Gnuplot Array Issue
by vbrtrmn (Pilgrim) on Jul 22, 2004 at 18:24 UTC
Re: Chart::Graph::Gnuplot Array Issue
by kryberg (Pilgrim) on Jul 22, 2004 at 18:31 UTC
    I've done it another way from the one already suggested.

    I use LWP::UserAgent to get data from a URL, save it to a file because it is a very large dataset I use more than once, do a bunch of manipulations, ultimately putting the data into arrays (@dates and @atemp in the code below) for various graphs, then graph.

    gnuplot({ "title" => "", "output type" => "png", "output file" => "temp.png", "x-axis label" => "$day.$month.$year $time - $eday.$emonth.$ey +ear $etime", "y-axis label" => "", "xdata" => "time", "format" => ["x", "%d.%m"], "timefmt" => "%Y-%m-%d-%H:%M", "xrange" => "[\"$dates[$index]\" : \"$dates[$j]\"]", "extra_opts" => join("\n","set grid", "set nokey", "set linest +yle 1 lt 3 l w 10","set lmargin 10","set rmargin 10","set tmargin 9","set bmargin 9 +" )}, [{ "style" => "lines ls 1", "type" => "columns"}, [@dates],[@atemp] ],); my $type = "AirTemp.png"; my $ftype = "Days" . "$days" . "ATemp.png"; my $finalgraph = printGraph($station,$type,$ftype); }
    In case anyone notices/wonders/tries to use this, some things are intentionally left blank and the file is called temp because I ultimately use GD to splice this onto a background image using the subroutine at the end called printGraph - I just thought I'd include the whole code block because I know it works.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://376385]
Approved by ysth
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-23 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found