NAME

GD::Graph::Cartesian - Make Cartesian Graphs with GD Package

SYNOPSIS

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;

DESCRIPTION

This is a wrapper around GD to place points and lines on a X/Y scatter plot.

CONSTRUCTOR

new

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
                    );

METHODS

addPoint

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

addLine

Method to add a line to the graph.

$obj->addLine(50=>25, 75=>35);
$obj->addLine(50=>25, 75=>35, [$r,$g,$b]);

addString

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

addLabel

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

addRectangle

$obj->addRectangle(50=>25, 75=>35);
$obj->addRectangle(50=>25, 75=>35, [$r,$g,$b]);

points

Returns the points array reference.

lines

Returns the lines array reference.

strings

Returns the strings array reference.

labels

Returns the labels array reference.

color

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;

font

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;

iconsize

draw

Method returns a PNG binary blob.

my $png_binary=$obj->draw;

OBJECTS

gdimage

Returns a GD object

gcnames

Returns a Graphics::ColorNames

PROPERTIES

width

height

ticksx

ticksy

borderx

bordery

rgbfile

minx

maxx

miny

maxy

INTERNAL METHODS

_scalex

Method returns the parameter scaled to the pixels.

_scaley

Method returns the parameter scaled to the pixels.

_imgxy_xy

Method to convert xy to imgxy coordinates

TODO

I'd like to add this capability into Chart as a use base qw{Chart::Base}

BUGS

Log on RT and email the author

LIMITS

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...

Similar CPAN Packages

Chart::Plot

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.

Chart

This is a great package for its support of legends, layouts and labels but it only support equally spaced x axis data.

GD::Graph

This is a great package for pie charts but for X/Y scatter plots it only supports equally spaced x axis data.

AUTHOR

Michael R. Davis qw/perl michaelrdavis com/

LICENSE

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.

SEE ALSO

GD::Graph::Cartesian, GD, Chart::Plot, Chart, GD::Graph