我有一个 Flec 条形图。它有一个酒吧系列。我需要在条形图的顶端显示数据标签。为此,我正在使用 labelFunction。这很好用。现在我想在同一个图表中添加一个 plotseries。一旦添加,条形系列中的标签功能将不起作用。标签不可见。有什么想法吗?谢谢
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
import mx.charts.series.items.PlotSeriesItem;
import mx.charts.series.items.BarSeriesItem;
import mx.charts.ChartItem;
import mx.controls.Label;
import mx.collections.ArrayCollection;
//Dataprovider for chart
[Bindable]
private var medalsAC:ArrayCollection = new ArrayCollection([
{ Country: "USA", Gold: 35, Silver:39, Bronze: 29,prevRank:"1",isIncrease:true },
{ Country: "China", Gold: 32, Silver:17, Bronze: 14,prevRank:"2",isIncrease:false }
]);
private function setCustomLabel(element:ChartItem):String {
var data:BarSeriesItem = BarSeriesItem(element);
return (data.item.prevRank).toString();
}
public function init(element:Object):String {
var data:PlotSeriesItem = PlotSeriesItem(element);
if(data.item.isIncrease){
return "images/increase.png";
}
else{
return "images/decrease.png";
}
}
]]></mx:Script>
<mx:VBox>
<mx:BarChart id="bar" showDataTips="true"
dataTipMode="multiple" >
<mx:verticalAxis>
<mx:CategoryAxis id="v1" categoryField="Country" dataProvider="{medalsAC}"/>
</mx:verticalAxis>
<mx:verticalAxisRenderers>
<mx:AxisRenderer placement="left" axis="{v1}"
verticalAxisTitleAlignment="vertical">
</mx:AxisRenderer>
</mx:verticalAxisRenderers>
<mx:series>
<mx:BarSeries id="bs2"
yField="Country"
xField="Silver"
dataProvider="{medalsAC}" labelFunction="setCustomLabel"
/>
<mx:PlotSeries id="plotSeries" yField="Country" xField="Silver" dataProvider="{medalsAC}"
displayName="Current Trend">
<mx:itemRenderer>
<mx:Component>
<mx:Image source="{outerDocument.init(data)}" horizontalAlign="center" height="16" width="16"/>
</mx:Component>
</mx:itemRenderer>
</mx:PlotSeries>
</mx:series>
</mx:BarChart>
</mx:VBox>
</mx:Application>