Here's a snippet from something I did with GD::Graph that read from a flat file:
foreach (@lines) { # Lines in the file look like: # Sun Jul 07 2002 10:03:03 Sensor 0 [100D973000080069] C: 25.1 F: +77.1 chomp; my ($day, $mon, $date, $year, $time, undef, $sensor, undef, undef, + $c, undef, $f) = split; push (@{$data[0]}, $day); push (@{$data[$sensor + 1]}, $f); $y_max = $y_max > $f ? $y_max : $f; $y_min = $y_min < $f ? $y_min : $f; } my $y_axis_max = ceil($y_max / 10) * 10; my $y_axis_min = floor($y_min / 10) * 10; my $y_ticks = ($y_axis_max - $y_axis_min) / 10; my $graph = new GD::Graph::lines(); $graph->set( x_label => 'Day', y_label => 'Temperature (F)', title => $title, y_max_value => $y_axis_max, y_min_value => $y_axis_min, y_tick_number => 16, y_label_skip => 2, box_axis => 1, line_width => 3, y_label_position => 1, x_label_skip => 48, x_tick_offset => 48, x_long_ticks => 1, transparent => 0, ); $graph->set_legend(@legend_labels); $graph->plot($data); save_chart($graph, "$img_path/$img_file");
Note that all arrays passed to plot() should be the same size. If they're not, pad the beginning of any short arrays with undef.

BTW, I've since switched from using a flat file to a MySQL database, and from GD::Graph to Chart::Graph::Gnuplot. I like Chart::Graph::Gnuplot because of the amount of control Gnuplot gives over the graph. If you've ever created Gnuplot input files yourself, you'll appreciate this module. Of course, some may consider it a drawback that it relies on an external program.


In reply to Re: Coaking GDGraph to work... by iguanodon
in thread Coaking GDGraph to work... by zakzebrowski

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.