1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| use strict;
use warnings;
use Text::CSV;
use GD::Graph::bars;
use GD::Graph::Data;
my $filename = "out.csv";
sub main {
print "Entrez la valeur : ";
my $val;
chomp( $val = <STDIN> );
open( INPUT, $filename ) or die "Cannot open $filename";
print "les pays ou les accident sont a cause du TraFic sont :\n";
my (@Pays, @Purcent) = ();
while ( my $line = <INPUT> ) {
chomp($line);
my (
$pays, $purcent,
) = split( ';', $line );
if ( $purcent > $val ) {
print "$pays\t$purcent\t\n";
push (@Pays, $pays);
push (@Purcent, $purcent);
}
}
close INPUT;
#print "@Pays\n";
#print "@Purcent\n";
graph(\@Pays, \@Purcent);
}
#NB : On passe les tableaux par référence - Ils ne sont pas modifiés dans graph()
sub graph{
my $Pays = shift;
my $Purcent = shift;
my $data = GD::Graph::Data->new([
[@$Pays],
[@$Purcent],
]) or die GD::Graph::Data->error;
my $graph = GD::Graph::bars->new;
$graph->set_title_font('c:\windows\fonts\timesbd.ttf', 22) or die $graph->error;
$graph->set_legend_font('c:\windows\fonts\timesbd.ttf', 14) or die $graph->error;
$graph->set_x_label_font('c:\windows\fonts\timesbd.ttf', 14) or die $graph->error;
$graph->set_y_label_font('c:\windows\fonts\timesbd.ttf', 14) or die $graph->error;
$graph->set_x_axis_font('c:\windows\fonts\timesbd.ttf', 14) or die $graph->error;
$graph->set_y_axis_font('c:\windows\fonts\timesbd.ttf', 10) or die $graph->error;
my $Xlabel = 'X Label';
my $Ylabel = 'Y Label';
$graph->set(
x_label => $Xlabel,
y_label => $Ylabel,
title => 'A Simple Bar Chart',
#y_max_value => 7,
#y_tick_number => 8,
#y_label_skip => 3,
x_labels_vertical => 1,
#bar_spacing => 10,
#shadow_depth => 4,
#shadowclr => 'dred',
transparent => 0,
) or die $graph->error;
$graph->plot($data) or die $graph->error;
my $file = 'bars.png';
open(my $out, '>', $file) or die "Cannot open '$file' for write: $!";
binmode $out;
print $out $graph->gd->png;
close $out
}
main(); |