The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

GD::Graph::Cartesian - Make cartesian graph using 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->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

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

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

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.

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;

draw

Method returns a PNG binary blob.

  my $png_binary=$obj->draw;

minx

maxx

miny

maxy

_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 cordinates

TODO

BUGS

Please send to the geo-perl email list.

LIMITS

AUTHOR

Michael R. Davis qw/perl michaelrdavis com/

LICENSE

Copyright (c) 2006 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 Geo::Constants Geo::Functions GD::Graph::Polar