Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different colours to different bars (perl graph)

Status
Not open for further replies.

JackTheRussel

Programmer
Aug 22, 2006
110
FI
Hi,

I have program which draw picture where are min, max and avg bars.

I have tried everything, but I can't set different colours to different bars.

Here is the program
Code:
#!/usr/bin/perl

use GD::Graph::bars3d; 
my $graph = new GD::Graph::bars3d( 400, 300 );

my @data = (
	    ["Min", "Max", "Avg"],
	    [ 2,  10,  5]
	    );

$graph->set(
	    x_label           => 'x_label title',
	    y_label           => 'y_label title',
	    title             => 'Head title',
	    dclrs             =>  [ qw(gold blue green) ],
	    );

my $gd = $graph->plot( \@data );
open(IMG, '>picture.png') or die $!;
binmode IMG;
print IMG $gd->png;

Here I try to set different colours to different bars
Code:
dclrs             =>  [ qw(gold blue green) ],

But it set all bars to gold-color.

And if I change order like this:
Code:
dclrs             =>  [ qw(blue gold green) ],

It set all bars to blue.

So what I have to do that I can set all tree bars into different colours ?
 
change the color, plot the next line, instead of doing it all in the one plot

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
PaulTEG.

Did you mean something like this?

Code:
my @data1 = (["min"],[2]);
my @data2 = (["max"],[8]);
my @data3 = (["avg"],[4]);

$graph->set( dclrs => [ qw(red) ] ); 
   my $gd = $graph->plot( \@data1 )

$graph->set( dclrs => [ qw(blue) ] ); 
   my $gd = $graph->plot( \@data2 )

$graph->set( dclrs => [ qw(yellow) ] ); 
   my $gd = $graph->plot( \@data3 )

If I do like this, then I get three bars which are
one after the other and it's not looking good ?
 
where did you see this?

dclrs => [ qw(gold blue green) ],

the GD::Graph module makes no mention of such a setting.





------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
OK, I see it now.

Just below that it says:

The first (fifth, ninth) data set will be green, the next pink, etc.

do you understand what that means? I don't because the documentation is quite long so I didn't read through it to try and find out.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top