I have a stacked bar chart with bars that need some custom labeling. Each bar needs to display the bar's value preceeded by a label. To support this, I have created a custom labelFunction for the various BarSeries in the BarChart (see below).
The function is successfully rendering the labels, but in the case of the stacked bars, the label values are not displaying what I want. Instead of showing the bar's value, it is showing the sum of the bars in the stack. For example, if a BarSet contains three bars with values 3, 4, and 5, the labels are being displayed not as "3", "4", and "5", but "3", "7", and "12".
From this example it looks like I can achieve the results I want by creating a separate labelFunction for each individual BarSeries and accessing the specific property (e.g. data.item.@fooCount). However, I'd prefer having just one generic function if possible. Is there another property I can access in place of xNumber that gets me the bar's particular value and not the sum?
Note that the default label behavior (i.e. not setting a labelFunction) displays the individual values, not the sums... So I'm assuming it's possible, hopefully without a lot of extra hoops to jump through. :)
My custom labelFunction:
private function setCustomLabel(item:ChartItem, series:Series):String
{
var data:BarSeriesItem = BarSeriesItem(item);
var currentSeries:BarSeries = BarSeries(series);
return currentSeries.displayName + ": " + data.xNumber;
}
A snippet of some of the BarChart code:
<mx:BarChart id="myChart" showDataTips="true"
height="180" width="100%">
...
<mx:BarSet type="stacked">
<mx:BarSeries displayName="Foo Count" xField="fooCount"
labelFunction="setCustomLabel" />
<mx:BarSeries displayName="Bar Count" xField="barCount"
labelFunction="setCustomLabel" />
</mx:BarSet>
</mx:series>
</mx:BarChart>
Thanks!