OK, so I now have the graph being built and being displayed in my html through an image tag. I'm still trying out GD::Graph printing through an IMG tag calling my script for now. I will try other methods next. However, I'm having some difficulty putting dynamic data into the plots. For example. Say I read in my parameters handed into my graph-building script and produce these variables:
# Width of graph my $width = $param{'width'}; # height of graph my $height = $param{'height'}; # Y Axis max value my $yMax = $param{'yMax'}; # Now let's setup the data for the graph: my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"] ); # all datasets separated by :: my $ds=1; # dataset counter # go through each dataset one at a time. foreach my $dataset(split(/::/, $param{'x'})) { my $i=0; # Go through each item in the dataset foreach my $num (split(/,/, $dataset)) { $data[$ds][$i++] = $num; } $ds++; } For the sake of making things easier, let's say that each dataset has exactly 10 integers separated by commas, and there are 2 datasets. So $param{'x'} would look something like this: "1,2,3,4,5,6,7,8,9,10::13,12,10,8,8,6,4,3,1,0" I get a broken image when I try to execute this (with the rest of the code listed below). If I manually setup @data it works fine. But if I try to us the data sent to the script, then it doesn't work. I have tested @data to make sure that my info is being stored; I simply do a print statment and take a look at specific spots in @data, like $data[1][4]. It it DOES print out the correct value '5'. I've tried several methods, but for some reason I can't seem to put the data in correctly. I know I must be doing something silly and small. Any ideas? Thanks. --Alex P.S. Ann, you're probably right that at some point I will need to hand some of this information to my script differently, as I am likely to surpass the 2048 character limit. But for now I'm just doing tiny tests :) Code: ---------------------------------------------------------------------------------- my $graph = GD::Graph::lines->new($width, $height); $graph->set( x_label => $param{'xLabel'}, y_label => $param{'yLabel'}, title => $param{'title'}, # Show the grid long_ticks => 0, # Show values on top of each bar show_values => 1, # Draw datasets in 'solid', 'dashed', 'dotted' and 'dotted-dashed' lines line_types => [1, 2, 3, 4], # Set the thickness of line line_width => 1, # Setting the max Y value y_max_value => $yMax, # Setting the number of values to show on Y axis y_tick_number => $yMax, # skip every __ values to display on Y axis y_label_skip => 1, dclrs => ['blue', 'green', 'red', 'cyan'] ) or die $graph->error; my $format = $graph->export_format; print header("image/$format"); binmode STDOUT; print $graph->plot([EMAIL PROTECTED])->$format(); On 12/6/05, Ricker, William <[EMAIL PROTECTED]> wrote: > > *> *Does anyone who has/does use GD::Graph know if there's an easy way > to > *> *embed the output graphs into HTML. > *> *Basically I'd like to be able to print a bunch of HTML, then the > graph, > *> *then some more HTML. > > [WDR] The basic techniques are to either > > (a) <img href="../graphs/123456789.png"> > Generate the graph to a 2nd file named with a random number (for security) > or a serial number (if no security needed) > > my $thisgraph; # uniq name > $this_graph = sprintf "%s/%d.png", $graphdir, rand($bignumber) > while -r $thisgraph; > print qq{<img href="$this_graph" size="$normal_size">}; > put_to_file($gd->png(), $this_graph); > > where put_to_file is something like (from GD::Image png method notes) > > sub put_to_file { > my ($data, $fn)[EMAIL PROTECTED]; > my $fh; > open $fh, "< $fh" or die; > binmode $fh; > print $fh $data or die; > close $fh or die; > } > > (b) <img > href="/scripts/imagemaker?x=17&y=42&title=%22Foo%20Bar%22&xname=X&yname=Y"> > Put the code that decides what to do from the Request in a module, and > call it from both the CGI or action module that generates the HTML page > (which generates the <img> link) and the CGI or action module that generates > the dynamic graphic (in response to the <img> link). Some amount of setup > work (varies with app) would have to be redone or saved in DB or some other > place (with unique names!), but at least the code is reused in a module. In > this case, you put all the request parameters that the graph module needs on > the IMG URI, or copy all the request parms to be safe if you don't know; > since it's a module, it should know. One module, one script could do both > Page and Image requests, with a arg difference (or HTTP context wanting > text/html or image/*?) determining which to generate. > > A has efficiency advantages in that any shared setup work for the page and > the graphic is done once. > B allows someone to statically deep link or bookmark an image. > B has efficiency advantages if page is likely to be fetched by Lynx or > WWW::Mechanize or spiders who will never fetch the image. > B has efficiency advantages if the pages will be fetched through Akamai or > client proxies, and multiple users may request the same image -- so the > image will be cached outside your server -- dont' recreate it if you don't > have to; this doesn't apply if everyone is local or every request is > unique. > > etc ... > > Bill n1vux > _______________________________________________ Boston-pm mailing list Boston-pm@mail.pm.org http://mail.pm.org/mailman/listinfo/boston-pm