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



ishaan
Novice

Jun 22, 2011, 12:02 PM


Views: 5404
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?


miller
User

Jun 22, 2011, 1:49 PM


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

Where's your code?

What are you currently using to generate a chart?

- Miller


ishaan
Novice

Jun 22, 2011, 2:38 PM


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

I am using the sample listed at:

http://linuxgazette.net/issue83/padala.html

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

my @itemdata = (["Item1", "Item2", "Item3"],
[80,90,100]);
my $mygraph = GD::Graph::bars->new(500, 300);
$mygraph->set(
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?


miller
User

Jun 22, 2011, 3:06 PM


Views: 5396
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