please help with GD::Graph

B

bev_greg

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.
 
B

Bob Walton

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::Dumper;
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(8);
}
}
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top