Skip to Content
Perl Graphics Programming
book

Perl Graphics Programming

by Shawn Wallace
December 2002
Beginner
478 pages
17h 55m
English
O'Reilly Media, Inc.
Content preview from Perl Graphics Programming

Let’s Make Some Graphs!

The GD::Graph package was written by Martien Verbruggen. It should run on any operating system on which the GD module is available. GD::Graph uses the GD module for all of its drawing and file primitives, and also relies on the GD::TextUtil package. Both packages are available from CPAN at http://www.cpan.org/authors/id/MVERB/.

Graph construction with GD::Graph can be broken into three phases. First you need to gather the data, parse it, and organize it in a form that you can pass to the graph drawing routines. Then you set the attributes of the graph such that it will come out the way you want it. Finally, you draw the graph with the plot( ) method.

The data for the graph must be in a very particular form before you plot the graph. The plotting methods expect a reference to an array, where the first element is a reference to an anonymous array of the x-axis values, and any subsequent elements are data sets to be plotted against the y axis. A sample data collection looks like this:

#!/usr/bin/perl -w use GD; # for font names use GD::Graph::lines; my @data = ( [ qw(1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 ) ], # timespan of data # thousands of people in New York [ 2, 5, 16.8, 18, 19, 22.6, 26, 32, 34, 39, 43, 48, 49, 49, 54.2, 58, 68, 72, 79 ], # thousands of people in SF [ 11, 18, 29.4, 35.7, 36, 38.2, 36, 41, 45, 49, 50, 51, 51.4, 52.6, 53.2, 54, 67, 73, 78 ], # thousands of people in Peoria [ 5, 8, 24, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Advanced Perl Programming

Advanced Perl Programming

Sriram Srinivasan
Perl by Example

Perl by Example

Ellie Quigley

Publisher Resources

ISBN: 9781449358280Errata Page