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
   | #!usr/bin/perl
use strict;
use DBI;
use Data::Dumper;
use GD;
use param
use GD::Graph::pie;
 
my $type = length(param("type")) ? param("type") : '';
my $data = length(param("data")) ? param("data") : '';
 
 
sub _make_pie {
    my ($title, $width, $height, $data1, $data2, $data3, $data4, $color1, $color2, $color3, $color4) = @_;
 
    # make data
    my $total = $data1 + $data2 + $data3 + $data4 ;
    my $data1_per = _percentage($data1, $total);
    my $data2_per = _percentage($data2, $total);
    my $data3_per = _percentage($data3, $total);
    my $data4_per = _percentage($data4, $total);
    my @labels = ("$data1 ($data1_per\%)", "$data2 ($data2_per\%)",
		  "$data3 ($data3_per\%)", "$data4 ($data4_per\%)");
    my @data = ([@labels], [$data1, $data2, $data3, $data4]);
 
    my $mygraph = GD::Graph::pie->new($width, $height);
 
    $mygraph->set(
		  pie_height              => 10,
                  title                   => $title,
		  dclrs                   => [$color1, $color2, $color3, $color4],
                  transparent             => 0,
                  ) or warn($mygraph->error);
 
    # print graph
    my $gd = $mygraph->plot(\@data) ;
	open(PNG, '>', "camembert.png") || die "Erreur d'ecriture : $!";
	binmode PNG;
	print PNG $gd->png;
	close PNG;	
}
 
 
if(defined($type) && length($type) && ($type eq 'pie')) {
		#Si l'id vaut 1 c'est le cas de Tous
		my ($title, $width, $height, $data1, $data2, $data3, $data4, $color1, $color2, $color3, $color4);
		if($data == 1){
			#pour le calcul de "Tous"
			my ($total_valid, $total_invalid, $total_waited, $total_returned) = (0,0,0,0);
 
			while(my ($cle, $value) = each(%decode_identifiant)){
				$total_valid += $$value[0];
				$total_invalid += $$value[1];
				$total_waited += $$value[2];
				$total_returned += $$value[3];
			}
			($title, $width, $height, $data1, $data2, $data3, $data4, $color1, $color2, $color3, $color4) = (
			$titles_pie[$data], 250, 250, $total_valid, $total_invalid, $total_waited, $total_returned,
			"green", "orange", "lgray", "red");
		}
		else{
			my $ref = $decode_identifiant{$data};
			($title, $width, $height, $data1, $data2, $data3, $data4, $color1, $color2, $color3, $color4) = (
			$titles_pie[$data], 250, 250, $$ref[0], $$ref[1], $$ref[2], $$ref[3], 
			"green", "orange", "lgray", "red");
		}   
		_make_pie($title, $width, $height, $data1, $data2, $data3, $data4, $color1, $color2, $color3, $color4);
} | 
Partager