Flex - 截断显示为字符串的十进制值

时间:2015-08-11 08:01:54

标签: actionscript-3 flex actionscript flex3 advanceddatagrid

我在我的flex应用程序中使用以下AdvancedDataGrid控件:

<mx:AdvancedDataGrid id="tableDataGrid" height="95%"  editable="false"  dataProvider="{tableDataGridLst}"
                sortableColumns="true" draggableColumns="false" resizableColumns="true" headerStyleName="adgHeaderStyle"
                textAlign="center" headerWordWrap="true"   verticalScrollPolicy="on" headerHeight="50"
                rowCount="{tableDataGridLst.length + 2}" >
                <mx:columns>
                    <mx:AdvancedDataGridColumn  headerText="Actual Hours Iet" dataField="actualhoursIet" dataTipField="actualhoursIet"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Actual Imp Iet" dataField="actualIet" dataTipField="actualIet"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Actual Hours 3PGH" dataField="actualhours3pgh" dataTipField="actualhours3pgh"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Actual Imp 3PGH" dataField="actual3pgh" dataTipField="actual3pgh"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Actual Hours RH" dataField="actualhoursrh" dataTipField="actualhoursrh"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Actual Imp RH" dataField="actualrh" dataTipField="actualrh"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />

                    <mx:AdvancedDataGridColumn  headerText="EMD AS" dataField="asValue" dataTipField="asValue"
                        width="60" textAlign="left"  headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="EMD TN" dataField="tnValue" dataTipField="tnValue"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Year" dataField="year" dataTipField="year"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />

                    <mx:AdvancedDataGridColumn  headerText="Month(AS)" dataField="monthAS" dataTipField="monthAS"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="No of Act(AS)" dataField="noOfActASCost" dataTipField="noOfActASCost"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <!--<mx:AdvancedDataGridColumn  headerText="Total Hours(AS) " dataField="hoursAS" dataTipField="hoursAS"
                        width="150" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    --><mx:AdvancedDataGridColumn  headerText="Month(TN)" dataField="monthTN" dataTipField="monthTN"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="No of Act(TN)" dataField="noOfActTNCost" dataTipField="noOfActTNCost"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Total Hours(1S/1F/1B)(TN)" dataField="hoursTN" dataTipField="hoursTN"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="Status Tracking(TN)" dataField="statusTracking" dataTipField="statusTracking"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />
                    <mx:AdvancedDataGridColumn  headerText="BAU(TN)" dataField="BAU" dataTipField="BAU"
                        width="60" textAlign="left" headerWordWrap="true" fontSize="11" showDataTips="true" />

                </mx:columns>                                                   
            </mx:AdvancedDataGrid>      

基本上,我从dataProvider tableDataGridList 获取数据,这些值基本上是小数,在条形图列上显示为字符串: Decimal data displayed as DataTip

我想要做的就是将这些十进制值截断为int值(如100.56到100),然后显示它们。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

您需要定义图表dataTipFunction来解决此问题。

chartInstance.dataTipFunction = myDataTipFunction

private function myDataTipFunction(hd:HitData):String
{
  return  hd.item.label + "\n " + Math.round(parseInt(hd.item.y));                  
}

取代&#34; hd.item.y&#34;您需要更新变量,例如&#34; hd.item.yourVariable&#34;。

通过这种方式,您可以自定义数据提示图表。

希望这对你有用。