Perl
  Home arrow Perl arrow Page 4 - 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 - Modifying the Graph, Continued
    ( Page 4 of 4 )

     

    The graph now looks a lot better than it did originally:

     

     

    However, there are two changes I can think of which should be made before the chart is perfect. First, the lines need to be given names other than “Dataset 1” and “Dataset 2.” In order to name these lines, the “legend_labels” element must be set. The value of this element must be a reference to an array. The elements of this array correspond to the names of the datasets. Let's name the first line “High” and the second line “Low”:

     

    $property{'legend_labels'} = ['High', 'Low'];

     

    The default color of the first line is appropriate, since red is associated with heat. However, the default color of the second line is not appropriate. Blue would be a much more appropriate color, since blue is associated with coldness.

    Fortunately, the color of anything in the graph can be changed using the “colors” element of the properties hash. The value of this element must be a hash. Within the colors hash, the colors of individual items can be changed. In order to change the color associated with a dataset, which is what we want to do, the “datasetN” property of this hash is set, where N is the zero-based number of the dataset we want to change. Let's go ahead and change the color of the second line, as well as explicitly specify the color of the first line:

     

    $property{'colors'} = {'dataset0' => [255, 0, 0], 'dataset1' => [0, 0,255]};

     

    Now the graph is perfect. It represents the data appropriately, which is the goal. The viewer can look at the graph and instantly tell what the graph represents, and he can see the general trend of the data. 

    Before we end, however, there is one more interesting thing I'd like to show you. Remember how each graph type corresponded to the name of a class? Well, let's say that we don't like the average monthly temperature represented by a line graph. Let's say that we'd rather have a bar graph. In order for us to change the graph from a line graph to a bar graph, we'd only have to substitute Chart::Lines for Chart::Bars in two places:

     

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

     

    The result is a bar graph which conveys the exact same data, but in another format:

     

     

    However, we only had to change two lines in the source code to achieve this. This consistency across multiple chart formats makes Chart particularly appealing. If you create a program that creates a chart of a particular type, and later want to change the type, then it's very easy to do so.

    Of course, there is more to Chart, including a lot more properties that can be changed to meet your needs, but, as you can see, the basics are very simple, making Chart an indispensable tool for data representation in Perl.



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