Created
September 23, 2014 12:57
-
-
Save SebDeclercq/74d73b7674101785dacc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pieChart { | |
use Moose; | |
has 'label', is => 'ro', isa => 'Str'; | |
has 'data', is => 'ro', isa => 'ArrayRef'; | |
has 'pcsuccess', is => 'ro', isa => 'Int'; | |
has 'pcerror', is => 'ro', isa => 'Int'; | |
sub png { | |
use GD::Graph::pie; | |
my $self = shift; | |
my $chart = GD::Graph::pie->new(); | |
my $colors = [qw/green red/]; | |
my $catego = [qw/success error/]; | |
my $data; | |
if (defined $self->data) { | |
$data = $self->data; | |
} else { | |
$data = [$self->pcsuccess,$self->pcerror]; | |
} | |
my @pie = ($catego,$data); | |
$chart->set(dclrs => $colors, | |
title => "% of SUCCESS(".uc($self->label).")"); | |
$chart->plot(\@pie); | |
open IMG,">",$self->label.".png" or die $!; | |
binmode IMG; | |
print IMG $chart->gd->png; | |
close IMG; | |
} | |
return 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl -w | |
use strict; | |
use warnings; | |
use feature 'say'; | |
use myFirstObject; | |
my $data = [55,45]; | |
my $name = "mon super gros essai"; | |
my $test = pieChart->new(label => $name,data => $data); | |
$test->png or die "Unable to create PNG chart : $!"; | |
my $essai = pieChart->new(label => 'second test', pcsuccess => 62, | |
pcerror => 28); | |
$essai->png or die "Unable to create PNG chart : $!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment