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

I’m using GIFgraph to create a line graph indicating the level of a lake from June 30, 1867 to the present. From 1931 I have monthly values. Prior to that the level was measured intermittently. From my research on GIFgraph (this is my first project with it), I learned that the x values (the dates in this case) aren’t treated truly as numeric. It assumes even spacing between the x-values. (If that is not the case, please tell me.) So, for the months prior to 1931 with no data, I entered the dates with “undef” for the level.

When I generate the graph, everything from 1931 on is great. Prior to that, the months with data are indicated by a vertical line starting at the bottom of the graph image, passing through the appropriate date on the x-axis and continuing on to the correct level as indicated on the y-axis. So from 1867 to 1931, I have vertical lines wherever there is data. From 1931, I have a line graph connecting the monthly lake values.

I know it is not connecting the values prior to 1931 because of all the undef. I there a way I can get those points to appear as points and everything after that as a line graph? Or even get the vertical line to just go from the x-axis to the appropriate y-value, rather than the bottom of the whole image to the y-value? Or does anybody know the appropriate way to handle such data with GIFgraph?

#!/usr/bin/perl 2 3 use strict; 26 # line chart class 27 use GIFgraph::lines; 28 use GD; 29 30 31 # create a new object 32 my $graph = new GIFgraph::lines(600,400); 33 34 $graph->set_title_font(gdMediumBoldFont); 35 $graph->set_x_label_font(gdMediumBoldFont); 36 $graph->set_y_label_font(gdMediumBoldFont); 37 $graph->set_x_axis_font(gdMediumBoldFont); 38 $graph->set_y_axis_font(gdMediumBoldFont); 39 $graph->set_legend_font(gdMediumBoldFont); 40 $graph->set(logo=>'80x22_green.gif',logo_resize=>.8,logo_posit +ion=> 'LR'); 41 $graph->set(textclr=>'black',labelclr=>'black',axislabelclr=>' +black',accentclr=>'black',bgclor=>'white ',fgclr=>'black',transparent=>0,x_label_skip=>300); 42 $graph->set(t_margin=>10,b_margin=>10,l_margin=>10,r_margin=>1 +0); 55 my @data = ( 56 [ @dates ], 57 [ @levels ], 58 [ @overflow ], 59 [ @low1992 ], 60 ); 61 62 my @legend = ( 'Lake Elevation', 'Overflow to Stump Lake', 'La +ke Level in 1992' ); 63 $graph->set_legend(@legend); 64 65 $graph->set ( 66 title => "05056500 Devils Lake near Devils Lake, North + Dakota", 67 x_label => "1867 to Present", 68 y_label => "Elevation (feet)", 69 y_max_value => 1455.00, 70 y_min_value => 1400.00, 71 y_tick_number => 11, 72 ); 73 74 binmode STDOUT; 75 76 my $image_name = "dvl_POR.gif"; 77 78 # Output the graph 79 $graph->plot_to_gif($image_name, \@data ); 80 81 print "$image_name was created."

Replies are listed 'Best First'.
Re: GIFGraph and undefined values
by crenz (Priest) on Apr 02, 2003 at 18:04 UTC

    I'm not really familiar with GIFGraph, so I guess I can't be of much help. However, have you looked at GD::Graph? GIFGraph actually is deprecated, and GD::Graph seems to offer more options anyway. Maybe you can find a solution in its documentation.

      Thank you for your reply. I'm working on a server controlled by another group within the organization. The modules installed are MODULE: GD version 1.19 and MODULE: GIFgraph version 1.10. The information you gave me may help prompt an installation of GD::Graph.
Re: GIFGraph and undefined values
by blokhead (Monsignor) on Apr 02, 2003 at 18:14 UTC
    I'm not familiar with GIFGraph either, but would recommend you consider using gnuplot. All you'd need to do is output all the (x,y) values to a file (coordinates whitespace separated, one point per line) from your Perl script, and gnuplot will make a nice graph from it.. just tell gnuplot plot 'datafile' with lines. Alternatively, there seem to be a few gnuplot interfaces for Perl on CPAN. In terms of plotting software, I believe gnuplot is very robust, and I've found there's usually a way to plot whatever I want with it.

    Sorry I can't give on-point advice about GIFGraph, but I hope this helps.

    blokhead

      Thanks for the information. As of right now, I do not have access to gnuplot, but this might help me get access to it.