ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  pie chart color issues
Posted by chris carlson on Feb-03-2023 03:06
i am passing data, labels, and colors as arrays into this function.
data and labels work just fine but i am not able to color the sectors

colors is an array of 0xffffff format color codes

setting one sector like this works
using both lines and the script dies

$c->sector(0)->setColor(0xd3d3d3);
#$c->sector(1)->setColor(0x80ff80);


using this, all sectors are black:
$c->setColors2($perlchartdir::DataColor, $colors);



############### function code: #################


my $piename = shift;    ## text
my $label = shift;  ## text graph title
my $data = shift;   ##input array
my $labels = shift; ## input array
my $colors = shift; ## input array

#  END INPUTS
# Create a PieChart object of size 360 x 300 pixels
my $c = new PieChart(360, 300);

# Set the center of the pie at (180, 140) and the radius to 100 pixels
$c->setPieSize(180, 140, 100);

# Add a title to the pie chart
$c->addTitle("$label utilization");


# Draw the pie in 3D
$c->set3D();

# Set the pie data and the pie labels
$c->setData($data, $labels);

# Set the sector colors
$c->setColors2($perlchartdir::DataColor, $colors);

#$c->sector(0)->setColor(0xd3d3d3);
#$c->sector(1)->setColor(0x80ff80);


# Explode the 1st sector (index = 0)
$c->setExplode(0);

# Output the chart
$c->makeChart("$chart_path/$piename");

  Re: pie chart color issues
Posted by Peter Kwan on Feb-03-2023 03:57
Hi Chris,

The $colors should refer to an array reference for an array of numbers. If it is black, I suspect it is not an array of numbers.

In Perl syntax, the following is a number:

0x123456

The following is not a number (it is a text string):

"0x123456"

In Perl, if the code expects a number, but the actual variable is not a number, Perl will automatically convert the non-number to a number by assuming it is a decimal number. So "0x123456" will be convert to 0, which is equivalent to 0x000000 in Perl. The color will be black.

I am not sure how you create the colors array. May be you can try to hard coded it to make sure it is an array of numbers:

#pass $my_colors as the argument to your chart plotting function
my $my_colors = [0xff9999, 0x9999ff, 0x66ff66];

If you must use text strings instead of numbers for the colors (eg. the colors are read from a text file, which are therefore text strings), please use the Perl hex function to convert them to numbers first.

Best Regards
Peter Kwan

  Re: pie chart color issues
Posted by chris carlson on Feb-03-2023 04:28
that was my issue. thank you very much for that quick answer.

  Re: pie chart color issues
Posted by chris carlson on Feb-03-2023 04:29
that is, i had it quoted so it was passing strings

  Re: pie chart color issues
Posted by BerryMaisie on Feb-03-2023 22:17
interesting information