GD::Graph

A graph plotting module for Perl 5
Download

GD::Graph Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Martien Verbruggen
  • Publisher web site:
  • http://search.cpan.org/~bwarfield/GDGraph-1.44/Graph/Data.pm

GD::Graph Tags


GD::Graph Description

A graph plotting module for Perl 5 GD::Graph is a graph plotting module for Perl 5.SYNOPSISuse GD::Graph::moduleName;GD::Graph is a perl5 module to create charts using the GD module. The following classes for graphs with axes are defined:GD::Graph::linesCreate a line chart.GD::Graph::bars and GD::Graph::hbarsCreate a bar chart with vertical or horizontal bars.GD::Graph::pointsCreate an chart, displaying the data as points.GD::Graph::linespointsCombination of lines and points.GD::Graph::areaCreate a graph, representing the data as areas under a line.GD::Graph::mixedCreate a mixed type graph, any combination of the above. At the moment this is fairly limited. Some of the options that can be used with some of the individual graph types won't work very well. Bar graphs drawn after lines or points graphs may obscure the earlier data, and specifying bar_width will not produce the results you probably expected.Additional types:GD::Graph::pieCreate a pie chart.USAGE:Fill an array of arrays with the x values and the values of the data sets. Make sure that every array is the same size, otherwise GD::Graph will complain and refuse to compile the graph. @data = ( , , );If you don't have a value for a point in a certain dataset, you can use undef, and the point will be skipped.Create a new GD::Graph object by calling the new method on the graph type you want to create (chart is bars, hbars, lines, points, linespoints, mixed or pie). my $graph = GD::Graph::chart->new(400, 300);Set the graph options. $graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 8, y_tick_number => 8, y_label_skip => 2 ) or die $graph->error;and plot the graph. my $gd = $graph->plot(@data) or die $graph->error;Then do whatever your current version of GD allows you to do to save the file. For versions of GD older than 1.19 (or more recent than 2.15), you'd do something like: open(IMG, '>file.gif') or die $!; binmode IMG; print IMG $gd->gif; close IMG;and for newer versions (1.20 and up) you'd write open(IMG, '>file.png') or die $!; binmode IMG; print IMG $gd->png;or open(IMG, '>file.gd2') or die $!; binmode IMG; print IMG $gd->gd2;Then there's also of course the possibility of using a shorter version (for each of the export functions that GD supports): print IMG $graph->plot(@data)->gif; print IMG $graph->plot(@data)->png; print IMG $graph->plot(@data)->gd; print IMG $graph->plot(@data)->gd2;If you want to write something that doesn't require your code to 'know' whether to use gif or png, you could do something like: if ($gd->can('png')) { # blabla }or you can use the convenience method export_format: my $format = $graph->export_format; open(IMG, ">file.$format") or die $!; binmode IMG; print IMG $graph->plot(@data)->$format(); close IMG;or for CGI programs: use CGI qw(:standard); #... my $format = $graph->export_format; print header("image/$format"); binmode STDOUT; print $graph->plot(@data)->$format();(the parentheses after $format are necessary, to help the compiler decide that you mean a method name there) Requirements: · Perl


GD::Graph Related Software