Perl
  Home arrow Perl arrow Basic Charting with Perl
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PERL

Basic Charting with Perl
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-05-20


    Table of Contents:
  • Basic Charting with Perl
  • Adding Data
  • Modifying the Graph
  • Modifying the Graph, Continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Basic Charting with Perl
    ( Page 1 of 4 )

    In programming, data manipulation is an everyday task. Programmers must be able to take raw data and perform some operation, or a set of operations, on that data to modify it. However, presenting data is also very important, both in programming and in other tasks. This article will cover one of the ways you can present data in Perl

    One way of presenting data is in a chart. There are a variety of chart types, each of which has its particular strength. Perl, not surprisingly, offers a wealth of modules for creating charts to present data. In this article, we'll examine a collection of modules, appropriately named Chart, that allows for the creation of charts. We'll take a look at using the module to create some basic charts. 

    Getting Started 

    There's very little to explain about charts in general that you don't already know, so let's jump right into the module by creating a basic chart. 

    The Chart module is, of course, available from CPAN, so obtaining it is simple:

     

    $ cpan Chart::Base

     

    Remember that Chart is actually a collection of modules, rather than a single module. Chart's usage reflects this. Instead of importing a single base module, as one might expect, we must actually import the module associated with the particular chart we want to create. Chart supports a number of chart types, but let's start with something simple. Say we want to graph average monthly temperatures for a particular city. A line graph would work well for this. So, let's use the Chart::Lines module:

     

    use Chart::Lines;

     

    Next, we have to instantiate a Chart::Lines object. Every operation is conducted through this object. The only parameters required are the desired width and height of the chart image. Let's make the chart 600 pixels wide and 400 pixels high:

     

    my $chart = new Chart::Lines(600, 400);

     

    Once a Chart::Lines object is instantiated, we can generate a complete chart with only a single method call. All we need is the name of the resulting image, and a reference to the data to be represented by the chart. The name of the image is a string, and the reference is to an array. 

    Let's assume that we already have data inside an array named @data, and that we want to create a chart named temps.png. To do this, we'd call the png method, like this:

     

    $chart->png('temps.png', @data);

     

    As you can see, there's not much to it. Of course, now we need some data. 



     
     
    >>> More Perl Articles          >>> More By Peyton McCullough
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek