|
Bar chart - two Y axex - display value |
Posted by Marta on Sep-27-2011 23:27 |
|
Hi,
I would like to show values in my chart over and under column. For data in first Y axis is ok, but for Y2 display
values sometimes have wrong position.
// Y1
$dataSetObj = $barLayerObj->addDataSet($data1,-1);
// Y1 - show values over and under column
$z = 0;
foreach($data1 as $n) {
$text = $barLayerObj->addCustomDataLabel(0, $z, "{value|2 ,}","arial.ttf", 8);
if ($n >= 0) {
$text->setPos(Center,-22);
}
else{
$text->setPos(Center,14);
}
$z++;
}//z
// Y2
$c->yAxis2->setColors(0x0000cc,0x0000cc,0x0000cc);
$dataSetObj2 = $barLayerObj->addDataSet($data2,-1);
$dataSetObj2->setUseYAxis2();
// Y2 - show values over and under column - where is ERROR ??
$z2 = 0;
foreach($data2 as $n2) {
$text2 = $barLayerObj->addCustomDataLabel(1, $z2, "{value|4 ,}","arial.ttf", 8, 0x0000cc);
if ($n2 >= 0) {
$text2->setPos(Center,-22);
}
else{
$text2->setPos(Center,14);
}
$z2++;
}//z2
Could you please help me how do I display values correctly?
Thank you.
|
Re: Bar chart - two Y axex - display value |
Posted by Peter Kwan on Sep-28-2011 02:11 |
|
Hi Marta,
I have tried your code and reproduced the same problem. I confirm this is a bug in ChartDirector. It occurs to "data label" when different datasets in the same bar layer are using different baselines (which can occur in a Multi-Bar Chart with different data sets using different axes).
However, the problem does not occur with "group" or "aggregate" labels (which are labels on the outside end points of the bars). So I suggest you may use group labels instead. The code you like:
for($z = 0; $z < count($data1); ++$z) {
$barLayerObj->addCustomGroupLabel(0, $z, "{value|2 ,}","arial.ttf", 8);
$barLayerObj->addCustomGroupLabel(1, $z, "{value|4 ,}","arial.ttf", 8, 0x0000cc);
}
(Note: The group labels are natually on the outside end points of the bars, so there is no need to "shift" them.)
Hope this can help.
Regards
Peter Kwan |
Re: Bar chart - two Y axex - display value |
Posted by Marta on Sep-28-2011 16:02 |
|
Your solution is great - Thank You!
Regards,
Marta |
|