|
PERL Variable type used for colors |
Posted by Donavon on Mar-14-2013 03:03 |
|
Hello...
I am trying to create a function that set's up a chart.
Currently having problem with the variable type for color.
This does not work..
my $color = "336699";
my $chartObjectBorderColor = "0x" . $color;
$c->setSectorStyle($perlchartdir::RoundedEdgeShading, $chartObjectBorderColor, 2);
Is there a special way that I need to call or use the variable in order for it to work in this context?
Thank You...
~Donavon |
Re: PERL Variable type used for colors |
Posted by Donavon on Mar-14-2013 06:48 |
|
I think I may have figured it out.
Let me know if this the proper way to do it. I also cleaned up the variable name to match what it's called in Chart Director.
my $color = "336699";
my $sectorEdgeColor = "0x" . $color;
$sectorEdgeColor = eval $sectorEdgeColor;
$c->setSectorStyle($perlchartdir::RoundedEdgeShading, $sectorEdgeColor, 2); |
Re: PERL Variable type used for colors |
Posted by Peter Kwan on Mar-14-2013 15:54 |
|
Hi Donavon,
ChartDirector colors are 32-bit integers. In your case, $color is not a number at all. (It has double quotes, and is therefore a text string.)
To use the integer 0x336699 as a number, you may set your variable to an integer. For example:
my $color = 0x336699;
my $sectorEdgeColor = $color;
If for some reason you must use a text string (such as if the data are read from a text file, or if the data are from a database, and the database schema is set up so that the color column is a text string), please use the Perl hex function to convert the text string to a number, before passing the number to ChartDirector. See:
http://perldoc.perl.org/functions/hex.html
Hope this can help.
Regards
Peter Kwan |
Re: PERL Variable type used for colors |
Posted by Donavon on Mar-15-2013 01:03 |
|
Hello Peter..
Thanks for your response.
The Color hex code is coming from a color wheel or text entry field on an html form. Can you please provide an example of what you are talking about.
my $color = "ffffff"; # return value from color wheel.
my $sectorEdgeColor = hex $color;
This is what is returned...
16777215
Thank You,
~Donavon |
Re: PERL Variable type used for colors |
Posted by Peter Kwan on Mar-15-2013 18:16 |
|
Hi Donavon,
The code you are using is already correct. The color ffffff is in fact 16777215, which is exactly equivalent to 0xffffff (the white color) accoriding to Perl syntax.
For example, you can try:
print 0xffffff;
It should display 16777215, which proves that the $sectorEdgeColor is already the color 0xffffff (the white color).
Hope this can help.
Regards
Peter Kwan |
|