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."
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.