Home: Perl Programming Help: Advanced:
Chart in perl : different color codes


Jun 22, 2011, 12:02 PM

Views: 5257
Chart in perl : different color codes

I am doing a chart in perl with X-axis ( Item Name) and Y-axis ( Percentage) and am able to display the chart in horizontal bars. Currently all the bars are showing the same color code and my requirement is to tag the data with certain color code.

Item Name Percent
Item 1 80 (Yellow)
Item 2 100 ( Green)
Item 3 60 (red)

I want to display the chart with different color codes for each of the item.

Can this be possible?


Jun 22, 2011, 1:49 PM

Views: 5255
Re: [ishaan] Chart in perl : different color codes

Where's your code?

What are you currently using to generate a chart?

- Miller


Jun 22, 2011, 2:38 PM

Views: 5252
Re: [miller] Chart in perl : different color codes

I am using the sample listed at:


use CGI ':standard';
use GD::Graph::bars;
use strict;

my @itemdata = (["Item1", "Item2", "Item3"],
my $mygraph = GD::Graph::bars->new(500, 300);
x_label => 'Item Data',
y_label => 'Item Name',
title => 'Sample Graph'

# Set colors for datasets
dclrs => ['blue'],
my $myimage = $mygraph->plot(\@itemdata) or die $mygraph->error;

print "Content-type: image/png\n\n";
print $myimage->png;

It sets the color to blue for all the items. What I am looking for is if I can set different color code to the data in the dataset ?

For example:

80 Red
90 Red
100 Green

Can this be possible even? Is there any other module that can support this?


Jun 22, 2011, 3:06 PM

Views: 5249
Re: [ishaan] Chart in perl : different color codes

Read the documentation. It'll tell you more than any of us can:

GD::Graph #colours

- Miller