<?xml version="1.0"?> <!-- charts/PredefinedAxisStyles.mxml --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <!--[CDATA[ //导入相关包 import mx.collections.ArrayCollection; import mx.charts.*; import mx.charts.series.items.ColumnSeriesItem; import mx.charts.ChartItem; import mx.charts.chartClasses.Series; import mx.charts.chartClasses.IAxis; import mx.utils.ObjectUtil; [Bindable] public var expenses:ArrayCollection = new ArrayCollection([ {Month:"Jan", Profit:20, Expenses:15}, {Month:"Feb", Profit:10, Expenses:20}, {Month:"Jun", Profit:30, Expenses:40}, {Month:"Aug", Profit:15, Expenses:25}, {Month:"Set", Profit:40, Expenses:45} ]); public function myLabelFormat(obj:Object,pcat:Object,ax:LinearAxis):String { return numForm.format(obj)+"%"; } private function setCustomLabel(element:ChartItem, series:Series):String { // Get a refereence to the current data element. var data:ColumnSeriesItem = ColumnSeriesItem(element); // Get a reference to the current series. var currentSeries:ColumnSeries = ColumnSeries(series); // Create a return String and format the number. return numForm.format(data.yNumber) + "%"; } public function myLabelDisplay(hd:HitData):String{ //return hd.displayText + "%"; // var curObj:Object = hd.item; // var curSeries:BarSeries = BarSeries(hd.chartItem.element); // 获得当前的BarSeries // return curObj.qual + "-" + curSeries.displayName + "/n" // + uqStatistics.getUQAs(curSeries.xField, curObj.qualObj).length // + RM.getString(BUNDLE_DASHBOARD, "label.piece"); var curObj:Object = hd.item; var curSeries:ColumnSeries = ColumnSeries(hd.chartItem.element); if(curSeries.yField == "Profit") return curSeries.yField + ":" + hd.item.Profit + "%"; else return curSeries.yField + ":" + hd.item.Expenses + "%"; } ]]--> </mx:Script> <mx:NumberFormatter id="numForm" useThousandsSeparator="true"/> <mx:Panel title="Using Predefined Axis Styles"> <mx:ColumnChart id="column" dataProvider="{expenses}" showDataTips="true" dataTipFunction="myLabelDisplay" > <mx:horizontalAxis> <mx:CategoryAxis dataProvider="{expenses}" categoryField="Month" /> </mx:horizontalAxis> <!-- 设置纵坐标读取的属性 --> <!-- 设置横坐标的最小刻度以及最大刻度,另外调用labelFunction重写刻度格式为百分比 --> <mx:verticalAxis> <mx:LinearAxis minimum="0" maximum="50" labelFunction="myLabelFormat"/> </mx:verticalAxis> <mx:series> <mx:ColumnSeries xField="Month" yField="Profit" displayName="Profit" labelPosition="outside" labelFunction="setCustomLabel" /> <mx:ColumnSeries xField="Month" yField="Expenses" displayName="Expenses" labelPosition="outside" labelFunction="setCustomLabel" /> </mx:series> </mx:ColumnChart> <mx:Legend dataProvider="{column}"/> </mx:Panel> <mx:Style> ColumnChart { horizontalAxisStyleName:myAxisStyles; verticalAxisStyleName:myAxisStyles; } .myAxisStyles { tickPlacement:none; } </mx:Style> </mx:Application>