2011-05-24 91 views
0

我已经在Adobe Flash Builder中创建了Columnchart。如何使用Adobe Flash Builder中的滑块控制列图表?

现在我想用Slider控制该柱形图。 我想根据滑块的值更改柱形图。

我该如何做到这一点?

任何建议是有帮助的。 在此先感谢!

+0

你的问题有点含糊。你使用什么Column Chart组件?那会是雅虎!雅特闪存组件?你正在使用哪个Slider组件? Flash中默认的一个?无论哪种方式,都应该有你正在使用的组件的文档。您需要在滑块上使用某种CHANGE事件侦听器,然后使用更新的滑块值更新所需的列。 – 2011-05-25 09:30:28

+0

@George嗨,其实我已经在Adobe flash builder4中创建了这个喜欢的仪表板.. – Smith 2011-05-25 09:33:07

+0

所以你使用的是Flex框架和Flash Builder IDE。这个问题应该重新标记。你在使用mx或spark组件吗? – 2011-05-25 09:42:18

回答

2

您需要将Change事件的侦听器添加到Slider组件。 然后您更新图表的数据提供者并将其重新分配给图表。 以下是Tour de Flex的修改示例。

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" 
    horizontalAlign="center" backgroundGradientColors="[0x000000,0x323232]" paddingTop="0" viewSourceURL="srcview/index.html"> 

    <mx:Script> 
     <![CDATA[ 

     import mx.collections.ArrayCollection; 

     [Bindable] 
     private var medalsAC:ArrayCollection = new ArrayCollection([ 
      { Country: "USA", Gold: 35, Silver:39, Bronze: 29 }, 
      { Country: "China", Gold: 32, Silver:17, Bronze: 14 }, 
      { Country: "Russia", Gold: 27, Silver:27, Bronze: 38 } ]); 
     //slider change handler 
     private function columnSliderChanged(event:Event):void{ 
      trace(columnSlider.value);//print slider 
      medalsAC.getItemAt(1).Gold = columnSlider.value * 10;//assign slider value to Gold for China (item index 1) 
      column.dataProvider = medalsAC;//re-assign data provider 
     } 
     ]]> 
    </mx:Script> 

    <mx:Panel title="ColumnChart Control" layout="horizontal" color="0xffffff" borderAlpha="0.15" width="600" height="240" 
     paddingTop="10" paddingRight="5" paddingBottom="10" paddingLeft="5" horizontalAlign="center"> 

     <mx:ColumnChart id="column" height="100%" color="0x323232" 
      showDataTips="true" dataProvider="{medalsAC}"> 

      <mx:horizontalAxis> 
       <mx:CategoryAxis categoryField="Country"/> 
      </mx:horizontalAxis> 

      <mx:series> 
       <mx:ColumnSeries xField="Country" yField="Gold" displayName="Gold"/> 
       <mx:ColumnSeries xField="Country" yField="Silver" displayName="Silver"/> 
       <mx:ColumnSeries xField="Country" yField="Bronze" displayName="Bronze"/> 
      </mx:series> 
     </mx:ColumnChart> 

     <mx:Legend dataProvider="{column}" color="0x323232"/> 

    </mx:Panel> 
    <!-- added a slider here, updates on dragging and has a change event handler --> 
    <mx:HSlider id="columnSlider" liveDragging="true" change="columnSliderChanged(event);"/> 
</mx:Application> 
+0

嘿...非常感谢...多数民众赞成什么我想...... :) – Smith 2011-05-25 10:08:19

+0

很高兴帮助,随时关闭您的重复问题(http://stackoverflow.com/questions/5946497/how -to-control-column-chart-with-hslider)在stackoverflow上保持干净。 – 2011-05-25 10:12:00

+0

是的......没有人回答如此说另一个1 ... :) – Smith 2011-05-25 10:48:04