It wasn’t until recently that I started to really use perl for my tasks. But the more I use it, the more I find myself enjoying it’s simple elegance and easy methods for transforming large complex sets of data into something meaningful. Whenever I find my self needed to analyze logs, I like to see them in the context of over time. This is far from the only way to visualize data, but it’s a basic one that I find useful time and time again. GD::Graph makes this task insanely easy.
All that’s required for a basic graph is a two-dimensional array. Essentially, an array containing two other arrays; one for the X-Axis values, and another for the Y-Axis. The little code below creates my data array, and sets the width/height of a new graph object.
my $graph = GD::Graph::area->new($width,$height);
Now all I need to do is plot the data on the graph object and extract a picture from it.
print STDOUT $image->png;
And that’s it! A very easy and straight forward method to get a simple graph of some data.