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
#!/usr/bin/perl -wT
use strict;
use CGI;
use GD::Graph::pie;
use constant TITLE => "Test";
my $csv = Text::CSV->new(); # create a new object
my $line;
my @data = ([ qw( Mon Tue Wed Thu Fri ) ]);
open (DATEI, "<","meinedaten.csv");
while( defined( $line = <DATEI> ) ) {
my $status = $csv->parse($line); # CSV felder parsen
if ($status) {
@columns = $csv->fields(); # da sind die Spalten
push @data, [ @colums ]; # Daten sichern
} else {
die ("Fehler: " . $csv->error_input ); # Fehler melden
}
}
close (DATEI);
my $q = new CGI;
my $graph = new GD::Graph::pie( 300, 300 );
$graph->set(
title => TITLE,
'3d' => 0
);
my $gd_image = $graph->plot( \@data );
print $q->header( -type => "image/png", -expires => "-1d" );
binmode STDOUT;
print $gd_image->png;