oren.gozlan
05-16-2005, 02:54 AM
Hi, i'm trying to use GD::line to generate a line graph.
I've taken the code from :
http://www.wdvl.com/Authoring/Languages/Perl/Weave/chart1-3.html
The question is, if the inputs for this line can be taken from a CSV file ?
My csv is like this (let say line.csv):
1,2,3,4,5,6,7,8,9
a,b,c,d,e,f,g,h,i,j
thnx... :)
The code is:
1 use strict;
2 use GD::Graph::lines;
3
4 my @data = (
5 ["Jan-01","Feb-01","Mar-01","Apr-01","May-01","Jun-01",
"Jul-01","Aug-01","Sep-01"],
6 [21,25,33,39,49,48,40,45,15],
7 [58,55,62,48,45,44,41,35,43]
8 );
9
10 my $graph = new GD::Graph::lines;
11
12 $graph->set(
13 x_label => 'Month',
14 y_label => 'Revenue ($1,000s)',
15 title => 'Monthly Revenue Trends for 2001',
16 x_labels_vertical => 1,
17 line_width => 3
18 )
19 or warn $graph->error;
20
21 $graph->set_legend( 'Online', 'Catalog' );
22
23 $graph->plot(\@data) or die $graph->error;
24
25 open(GRAPH,">graph4.jpg") || die "Cannot open graph4.jpg: $!\n";
26 binmode GRAPH;
27 print GRAPH $graph->gd->jpeg(100);
28 close GRAPH;
I've taken the code from :
http://www.wdvl.com/Authoring/Languages/Perl/Weave/chart1-3.html
The question is, if the inputs for this line can be taken from a CSV file ?
My csv is like this (let say line.csv):
1,2,3,4,5,6,7,8,9
a,b,c,d,e,f,g,h,i,j
thnx... :)
The code is:
1 use strict;
2 use GD::Graph::lines;
3
4 my @data = (
5 ["Jan-01","Feb-01","Mar-01","Apr-01","May-01","Jun-01",
"Jul-01","Aug-01","Sep-01"],
6 [21,25,33,39,49,48,40,45,15],
7 [58,55,62,48,45,44,41,35,43]
8 );
9
10 my $graph = new GD::Graph::lines;
11
12 $graph->set(
13 x_label => 'Month',
14 y_label => 'Revenue ($1,000s)',
15 title => 'Monthly Revenue Trends for 2001',
16 x_labels_vertical => 1,
17 line_width => 3
18 )
19 or warn $graph->error;
20
21 $graph->set_legend( 'Online', 'Catalog' );
22
23 $graph->plot(\@data) or die $graph->error;
24
25 open(GRAPH,">graph4.jpg") || die "Cannot open graph4.jpg: $!\n";
26 binmode GRAPH;
27 print GRAPH $graph->gd->jpeg(100);
28 close GRAPH;