2010-11-14 23 views

Répondre

1

Ou vous pouvez utiliser GD :: Graph

use strict; 
use GD::Graph::bars; 
use GD::Graph::hbars; 
use GD::Graph::Data; 

#For some reason, installing GD::Graph didn't put save.pl in my @INC path 
require "/usr/share/doc/libgd-graph-perl/examples/samples/save.pl"; 

my $data = GD::Graph::Data->new([ 
    ["Item 1","Item 2","Item 3"], 
    [1234, 5678, 910112], 
    ]) or die GD::Graph::Data->error; 

my @names = qw/GDbars123 GDbars123-h/; 

for my $my_graph (GD::Graph::bars->new, GD::Graph::hbars->new) 
{ 
    my $name = shift @names; 

    print STDERR "Processing $name\n"; 

    $my_graph->set( 
    x_label   => 'X Label', 
    y_label   => 'Y label', 
    title   => 'A Simple Bar Chart', 
    #y_max_value  => 8, 
    #y_tick_number => 8, 
    #y_label_skip => 2, 

    #x_labels_vertical => 1, 

    # shadows 
    bar_spacing  => 8, 
    shadow_depth => 4, 
    shadowclr  => 'dred', 

    transparent  => 0, 
    ) 
    or warn $my_graph->error; 

    $my_graph->plot($data) or die $my_graph->error; 
    save_chart($my_graph, $name); 
}