Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Drawing a line chart with GD::Graph::lines - Page 20

November 12, 2001

The sales director would also like a line graph for online and catalog sales so that she can get provide sales trends information to the other managers. To do this, we need to use the GD::Graph::lines module. The source code still looks similar to our other graphs, though a few of the set() parameters have been replaced with line chart parameters. The x_labels_vertical parameter on line 16 draws the x labels vertically rather than horizontally in all of the previous graphs. The line_width parameter specifies the number of pixels wide to draw the lines in the chart.

1  use strict;
2  use GD::Graph::pie;
3
4  my @data = (
5  	    ["Online","Catalog","
 Storefront","Resellers"],
6  	    [156,241,55,28]
7  	    );
8
9  my $graph = new GD::Graph::pie(275, 275);
10
11  $graph->set(
12      title           => 'Revenue by Category for 2001',
13      label           => 'Category',
14      axislabelclr    => 'black',
15      '3d'            => 1,
16      start_angle     => 90,
17      suppress_angle => 5,
18  )
19  or warn $graph->error;
20
21  $graph->set_value_font
 ("/usr/share/fonts/ttf/windows/times.ttf",12);
22
23  $graph->plot(\@data) or die $graph->error;
24
25  open(GRAPH,">graph5.jpg") || die "Cannot
 open graph5.jpg: $!\n";
26  print GRAPH $graph->gd->jpeg(100);

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  print GRAPH $graph->gd->jpeg(100);

[The colored lines above are one line. They have been split for formatting purposes.]

Drawing A Comparative Bar Graph - Page 19
Weaving Magic With Regular Expressions
Drawing a pie chart with GD::Graph::pie - Page 21


Up to => Home / Authoring / Languages / Perl / Weave




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers