|
conditional data label formatting |
Posted by James M on Mar-18-2009 03:56 |
|
I'm working on a bar graph in Chartdirector 4.1 (PHP), and I can't figure out how to do a couple things.
I understand that "Aggregate labels" are displayed above the bar, and "data labels" are displayed inside the bar.
I have a percentage bar graph where I'd like:
* values above a threshold (80% or so) display the values INSIDE the bar (a 'data' label), so the labels don't crash into the top of the bar.
* values below that threshold are displayed ON TOP OF the bar (like an 'aggregate' label), so that values of 0-10% can be displayed without crashing into the bottom of the graph or X-Axis labels.
* Percentages that are exactly even (like 100.0%) are displayed as {value|0}, but other values (like 95.2%) are displayed as {value|1}.
I'm very close, but I'm having trouble with these last few little issues. Is this possible??
Any help is appreciated. |
Re: conditional data label formatting |
Posted by Peter Kwan on Mar-18-2009 13:53 |
|
Hi James,
If you have custom or complicated rules to format and position the labels, it is better to code those custom rules using PHP, instead of using ChartDirector API (which is not a programming language, and therefore is not as powerful as PHP in representing custom rules).
In your case, when coded your rules in PHP, it may use something like (assuming your data are from 0 - 100)
for ($i = 0; $i < count($data); ++$i) {
#this is your label formatting rule
$label = (round($data[$i] * 10) % 10 == 0) ? "{value|0}" : "{value|1}";
#this is your label positioning rule
if ($data > 80)
$layer->addCustomAggregateLabel($i, $label);
else
$layer->addCustomDataLabel(0, $i, $label);
}
Hope this can help.
Regards
Peter Kwan |
Re: conditional data label formatting |
Posted by James M on Mar-18-2009 23:07 |
|
Yes, thank you! I was unaware of the addCustomDataLabel and addCustomAggregateLabel functions! That's exactly what I was looking for! |
|