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

Message ListMessage List     Post MessagePost Message

  custom label on sidebar chart
Posted by at on Sep-26-2012 18:22
Attachments:
Hi Peter, how can I add a custom label on a sidebar chart? I referred to the stackedbar
chart sample but couldn't get it right when the label is custom e.g. as extrafield. The code
below generates the attached chart. Only the first label of x-axis has the custom label
while the others do not have.

$i = 0;
$this->barLayer = $c->addBarLayer2(Side);
foreach($this->barDataArray as $key => $dataArray) {
       $this->barLayer->addDataSet($dataArray, $this->transparentColors[$i], $legend);
       if(isset($this->extraFields[$i]) && $this->extraFields[$i]) {
                $this->barLayer->addExtraField($this->extraFields[$i]);
                $this->barLayer->addCustomDataLabel($i, 0, "{dsdiField0}");
       }
       $i++;
}

Thanks.
sidebar.png
sidebar.png

24.06 Kb

  Re: custom label on sidebar chart
Posted by Peter Kwan on Sep-27-2012 02:11
Hi at,

If you have two data arrays (two data sets), then you need two extra field arrays. The code is like:

$this->barLayer = $c->addBarLayer2(Side);
foreach($this->barDataArray as $key => $dataArray) {
       $this->barLayer->addDataSet($dataArray, $this->transparentColors[$i], $legend);
       $this->barLayer->addExtraField($this->extraFields[$i]);
       $i++;
}
$this->barLayer->setDataLabelFormat("{dsdiField0}");


In the above code, $this->extraFields[$i] is an array that contains the labels for the bars of color $this->transparentColors[$i]. ($this->extraFields is therefore an array of arrays.) The $this->extraFields[$i] array should be of the same length as that of the $dataArray. So if you have 12 elements in the $dataArray, the $this->extraFields[$i] should also have 12 elements for the 12 labels. If there is no label for a particular bar, please use an empty string "" as the label.

Hope this can help.

Regards
Peter Kwan

  Re: custom label on sidebar chart
Posted by at on Sep-27-2012 11:26
Attachments:
Hi Peter, thanks, it's working but there's a slight problem, there are bars that do display
the labels,  I can confirm the data since the mouseover is showing the 'Count' which
should be the same as the label.  Pls see attached. The code is now below,

$this->barLayer = $c->addBarLayer2(Side);
foreach($this->barDataArray as $key => $dataArray) {
         $this->barLayer->addDataSet($dataArray,$this->transparentColors[$i],$legend);
         $this->barLayer->addExtraField($this->extraFields[$i]);
         $i++;
}
        $this->barLayer->setDataLabelFormat("{dsdiField0}");
        $label_obj = $this->barLayer->setDataLabelStyle();
        $label_obj->setPos(0, -15);
side_bar2.png
side_bar2.png

27.89 Kb

  Re: custom label on sidebar chart
Posted by Peter Kwan on Sep-27-2012 22:45
Hi at,

The data label is supposed to be inside the bar segment. By default, ChartDirector will not show the data label if the bar segment is so small that there is insufficient space for the data label. For your case, although you have use setPos to move the labels, ChartDirector will hide the label if the bar segment is too small. To force ChartDirector to show all labels, you may use BarLayer.setMinLabelSize:

#show the label even if the bar height is 0
$this->barLayer->setMinLabelSize(0);

Hope this can help.

Regards
Peter Kwan

  Re: custom label on sidebar chart
Posted by at on Sep-28-2012 10:00
Hi Peter, thanks for the great support.