GD::Graph::Cartesian - Make Cartesian Graphs with GD Package
use GD::Graph::Cartesian; my $obj=GD::Graph::Cartesian->new(height=>400, width=>800); $obj->addPoint(50=>25); $obj->addLine($x0=>$y0, $x1=>$y1); $obj->addRectangle($x0=>$y0, $x1=>$y1); $obj->addString($x=>$y, 'Hello World!'); $obj->addLabel($pxx=>$pxy, 'Title'); #for labels on image not on chart $obj->font(gdSmallFont); #sets the current font from GD exports $obj->color('blue'); #sets the current color from Graphics::ColorNames $obj->color([0,0,0]); #sets the current color [red,green,blue] print $obj->draw;
This is a wrapper around GD to place points and lines on a X/Y scatter plot.
The new() constructor.
my $obj = GD::Graph::Cartesian->new( #default values width=>640, #width in pixels height=>480, #height in pixels ticksx=>10, #number of major ticks ticksy=>10, #number of major ticks borderx=>2, #pixel border left and right bordery=>2, #pixel border top and bottom rgbfile=>'/usr/X11R6/lib/X11/rgb.txt' minx=>{auto}, #data minx miny=>{auto}, #data miny maxx=>{auto}, #data maxx maxy=>{auto}, #data maxy points=>[[$x,$y,$color],...], #addPoint method lines=>[[$x0=>$y0,$x1=>$y1,$color],...] #addLine method strings=>[[$x0=>$y0,'String',$color],...] #addString method );
Method to add a point to the graph.
$obj->addPoint(50=>25); $obj->addPoint(50=>25, [$r,$g,$b]); $obj->addPoint(50=>25, [$r,$g,$b], $size); #size default iconsize 7 $obj->addPoint(50=>25, [$r,$g,$b], $size, $fill); #fill 0|1
Method to add a line to the graph.
$obj->addLine(50=>25, 75=>35); $obj->addLine(50=>25, 75=>35, [$r,$g,$b]);
Method to add a string to the graph.
$obj->addString(50=>25, 'String'); $obj->addString(50=>25, 'String', [$r,$g,$b]); $obj->addString(50=>25, 'String', [$r,$g,$b], $font); #$font is a gdfont
Method to add a label to the image (not the graph).
$obj->addLabel(50=>25, 'Label'); #x/y pixels of the image NOT units of the chart $obj->addLabel(50=>25, 'Label', [$r,$g,$b]); $obj->addLabel(50=>25, 'Label', [$r,$g,$b], $font); #$font is a gdfont
$obj->addRectangle(50=>25, 75=>35); $obj->addRectangle(50=>25, 75=>35, [$r,$g,$b]);
Returns the points array reference.
Returns the lines array reference.
Returns the strings array reference.
Returns the labels array reference.
Method to set or return the current drawing color
my $colorobj=$obj->color('blue'); #if Graphics::ColorNames available my $colorobj=$obj->color([77,82,68]); #rgb=>[decimal,decimal,decimal] my $colorobj=$obj->color;
Method to set or return the current drawing font (only needed by the very few)
use GD qw(gdGiantFont gdLargeFont gdMediumBoldFont gdSmallFont gdTinyFont); $obj->font(gdSmallFont); #the default $obj->font;
Method returns a PNG binary blob.
my $png_binary=$obj->draw;
Returns a GD object
Returns a Graphics::ColorNames
Method returns the parameter scaled to the pixels.
Method to convert xy to imgxy coordinates
I'd like to add this capability into Chart as a use base qw{Chart::Base}
Log on RT and email the author
There are many packages on CPAN that create graphs and plots from data. But, each one has it's own limitations. This is the research that I did so that hopefully you won't have to...
This is the second best package that I could find on CPAN that supports scatter plots of X/Y data. However, it does not supports a zero based Y-axis for positive data. Otherwise this is a great package.
This is a great package for its support of legends, layouts and labels but it only support equally spaced x axis data.
This is a great package for pie charts but for X/Y scatter plots it only supports equally spaced x axis data.
Michael R. Davis qw/perl michaelrdavis com/
Copyright (c) 2009 Michael R. Davis (mrdvt92)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
GD::Graph::Cartesian, GD, Chart::Plot, Chart, GD::Graph
To install GD::Graph::Cartesian, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GD::Graph::Cartesian
CPAN shell
perl -MCPAN -e shell install GD::Graph::Cartesian
For more information on module installation, please visit the detailed CPAN module installation guide.