Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Coaking GDGraph to work...

by iguanodon (Curate)
on Feb 04, 2003 at 14:11 UTC ( #232526=note: print w/ replies, xml ) Need Help??


in reply to Coaking GDGraph to work...

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.


Comment on Re: Coaking GDGraph to work...
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://232526]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2015-07-06 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (69 votes), past polls