2012-05-09 62 views
0

我使用的是FlashBuilder 4.6,Coldfusion 9和Sql Server 2005以每年一個人的數據填充折線圖。如果我在數據提供程序中使用固定字符串,這很好,但我想通過使用所有可用個人的下拉列表來選擇個人。用於折線圖的個人名稱與下拉列表中的個人名稱格式相同。 flashbuilder數據/服務將這些字段顯示爲MS Sql Server表將其顯示爲varchar(50)的字符串。如何從下拉菜單中使用selectedItem填充FlashBuilder 4.6中的折線圖

附加代碼顯示getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1('greenleaf')選擇單個'greenleaf'。我想從下拉列表中將它替換爲selectedItem,以使圖表具有動態性。我嘗試用({dropdownList.selectedItem})替換('greenleaf'),但它可能不起作用,但也許我需要觸發一個事件才能使其工作。

我是FlashBuilder和Flex的新手,但已經做了大量的閱讀並沒有發現任何結論。

任何幫助將非常感激。 謝謝, 威爾

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" 
       xmlns:pool_ratings_yr1service="services.pool_ratings_yr1service.*" 
       xmlns:pool_playerservice="services.pool_playerservice.*" 
       minWidth="955" minHeight="600"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 
      import mx.events.FlexEvent; 

      protected function linechart1_creationCompleteHandler(event:FlexEvent):void 
      { 
       getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1('greenleaf'); 
      } 


      protected function dropDownList_creationCompleteHandler(event:FlexEvent):void 
      { 
       getAllpool_playerResult.token = pool_playerService.getAllpool_player(); 
      } 

     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <s:CallResponder id="getpool_ratings_yr1Result"/> 
     <pool_ratings_yr1service:Pool_ratings_yr1Service id="pool_ratings_yr1Service" 
                 fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
                 showBusyCursor="true"/> 
     <s:CallResponder id="getAllpool_ratings_yr1Result"/> 
     <s:CallResponder id="getAllpool_playerResult"/> 
     <pool_playerservice:Pool_playerService id="pool_playerService" 
               fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
               showBusyCursor="true"/> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <mx:LineChart id="linechart1" x="234" y="97" 
        creationComplete="linechart1_creationCompleteHandler(event)" 
        dataProvider="{getpool_ratings_yr1Result.lastResult}" showDataTips="true"> 
     <mx:series> 
      <mx:LineSeries id="lineSeries" displayName="Series 1" yField="avg_rating"/> 
     </mx:series> 
     <mx:horizontalAxis> 
      <mx:CategoryAxis id="categoryAxis" categoryField="yr"/> 
     </mx:horizontalAxis> 
    </mx:LineChart> 
    <mx:Legend dataProvider="{linechart1}"/> 
    <s:DropDownList id="dropDownList" x="73" y="133" 
        creationComplete="dropDownList_creationCompleteHandler(event)" 
        labelField="lname"> 
     <s:AsyncListView list="{getAllpool_playerResult.lastResult}"/> 
    </s:DropDownList> 
</s:Application> 

回答

0

嘗試添加功能:

private function comboBoxChange():void 
{ 
    var selectedName:String = dropDownList.selectedItem; 
    getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1(selectedName); 

} 

然後在您的下拉列表中添加一個變化事件監聽:

<s:DropDownList id="dropDownList" x="73" y="133" 
       creationComplete="dropDownList_creationCompleteHandler(event)" 
       labelField="lname" 
       change="comboBoxChange()"> 
+0

感謝您的意見,大教堂。我在沒有改變任何其他代碼的情況下嘗試了這一點,當我從下拉列表中選擇一個名稱時,折線圖數據行消失了。我需要替換此行中的任何內容嗎?:getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1('greenleaf'); –

+0

getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1('greenleaf');是你的圖表開始的。如果你不想讓它從任何東西開始,直到選擇一個名字,你可以把它們放在一起。至於在選擇名稱時沒有獲取數據,請添加「import mx.controls.Alert;」並在comboBoxChange函數內添加「Alert.show(dropDownList.selectedItem)」。如果警報顯示「對象對象」,則更改var selectedName:String = dropDownList.selectedItem;被選爲var selectName:String = dropDownList.selectedItem.lname;並看看會發生什麼。 – Dom

+0

最後更改var selectedName:String = dropDownList.selectedItem.lname;有所作爲。我現在得到一個更改的數據行,但是彈出框顯示「[object Playername_returntype]」,它是下拉lname的返回類型的名稱。一旦我點擊這個盒子好的一切看起來不錯。有沒有辦法抑制這個盒子?這令人興奮。 –