Thanks to all the responses, I got this working having the image src call a separte cgi program.
<img src="test4.pl?sta=$station&const=$constituent" alt="$station $constituent" border="1">
#!/usr/bin/perl -w # test4.pl for testing real-time graph capabilities # November 9, 2004 use CGI qw( :standard ); use CGI::Carp 'fatalsToBrowser'; my $q = new CGI; my $station = $q->param('sta'); my $constituent = $q->param('const'); my $combined = "$station" . "$constituent"; my $img = `/usr/local/bin/gnuplot $station $constituent $combined`; print $q->header("image/png"), $img;
However, because I need to change the gnuplot set commands based on user input, I want to do this differently. Something like
#!/usr/bin/perl -w # test5.pl for testing real-time graph capabilities # November 17, 2004 use CGI qw( :standard ); use CGI::Carp 'fatalsToBrowser'; #will print error message to user $CGI::POST_MAX = 512; # limit maximum posting size to 512 bytes $CGI::DISABLE_UPLOADS = 1; # disables uploading files entirely my $q = new CGI; my $data = "05056670.txt"; print $q->header("image/png\n\n"); my $img = plotdata(); sub plotdata { open my $graph => "| /usr/local/bin/gnuplot" or die "Failed to open +pipe: $!\n"; print $graph <<"gnu"; set terminal png color set output set xdata time set timefmt "%Y%m%d" set key left top title "Legend" box set grid xtics ytics set yrange [700:] set format x "%Y" set xlabel "Year" set ylabel "Sodium, water, filtered, milligrams per liter" set title "05056670 Western Stump Lake Major Ions" plot "$data" using 2:3 title "P00930 Sodium dissolved" gnu close $graph or die "Failed to close pipe: $!\n"; }

When I try this, I get:
PNG

IHDRsBITLˢ0PLTEUUUUUUUUUUUUIN.tEXtSoftwaregnuplot Unix version 3.7 patchlevel 1CIDATxKң`3&5e'5eHJ@ !tt ?i    Cۗn4oam]$붛lϐ>a~of&w0߇Nܺ aٍۇ):M}ݍ:MQuaJn>uF}zYO/$$Gg\5l=oOe-LfeƧ’.&<)9դ1mt6v0QfN.T#F}!YuSԏzcn@7(Mr;


in the browser.

What am I doing wrong?

In reply to Re: gnuplot and CGI by kryberg
in thread gnuplot and CGI by kryberg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.