Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > please help with GD::Graph

Reply
Thread Tools

please help with GD::Graph

 
 
bev_greg@yahoo.com
Guest
Posts: n/a
 
      07-31-2005
I want to create a line graph that has more than 7 datasets, which
looks like ([time], [interface 1 data], [interface 2 data], ......
[interface 30 data]), I didn't find a way to distingush which line is
the data for which interface except using @legend, does anyone know how
many colors can be used, does it support more than 30 colors? or, is
there a way that I can have a dataset name printed for each line in the
graph? Thanks for your help.

 
Reply With Quote
 
 
 
 
Bob Walton
Guest
Posts: n/a
 
      07-31-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I want to create a line graph that has more than 7 datasets, which
> looks like ([time], [interface 1 data], [interface 2 data], ......
> [interface 30 data]), I didn't find a way to distingush which line is
> the data for which interface except using @legend, does anyone know how
> many colors can be used, does it support more than 30 colors? or, is
> there a way that I can have a dataset name printed for each line in the
> graph? Thanks for your help.
>


Please try to communicate in Perl, not some pseudo language. We
speak Perl in this newsgroup. Also, please show what you have
done so far, and state what it is that you thought it should do
and what it actually did. Keep the code to as small as possible
to illustrate your problem, and make it so anyone can
copy/paste/run it.

Your questions are readily answered by perusing the documentation
for the GD::Graph module and its submodules.

Per that documentation, by default, datasets cycle through 7
colors, but you can add to that list easily using the dclrs method.

You can add additional colors to the defined colors list with the
add_colour method of GD::Graph::colour. Using the colour_list
function, one sees that there are actually 29 already-defined
colors, so it looks like you would have to add only one more.

Here is a crappy little program that draws a 30-line graph with
each line in a different color:

use GD::Graph::lines;
use strict;
use warnings;
use Data:umper;
use GD::Graph::colour qw(:lists :colours);
add_colour(funky=>[23,234,127]);
my @colors=colour_list(30);
print Dumper(\@colors);
my @data;
for my $i(0..30){
for my $j(0..5){
$data[$i][$j]=$j,next if $i==0; #x labels
$data[$i][$j]=rand(;
}
}
print Dumper(\@data);
my $graph = GD::Graph::lines->new(1000, 800);
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Some simple graph',
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2
) or die $graph->error;
$graph->set(dclrs=>\@colors);
my $gd = $graph->plot(\@data) or die $graph->error;
open(IMG, '>junk541.gif') or die $!;
binmode IMG;
print IMG $gd->gif;
close IMG;

HTH.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please please please help this guy with his open source java app casioculture@gmail.com Java 4 05-05-2005 08:24 AM
Console profile for Windows app in VC++ - PLEASE PLEASE PLEASE HELP! MuZZy C++ 7 01-07-2005 08:40 PM
Computer problems please please please help Nick Computer Support 0 06-04-2004 08:49 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments