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

Flex - Truncate decimal values displayed as strings

我在我的 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 获取数据,值基本上是小数,在条形图列上显示为字符串:

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

您需要定义图表数据提示功能来解决这个问题。

chartInstance.dataTipFunction = myDataTipFunction

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

代替 "hd.item.y",您需要像 "hd.item.yourVariable" 一样更新您的变量。

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

希望这对你有用。