0 Replies Latest reply on Mar 4, 2009 7:02 PM by kemah551

    array collect refresh issue

    kemah551
      I'm having problems with my chart updating when new values are updated via either a slider or NumericStepper. I'm stuck on how to handle this.

      Any help would be much appreciated.

      Thanks.

      here is the code.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="com.fusioncharts.components.*" viewSourceURL="srcview/index.html" creationComplete="init()" >


      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.formatters.NumberBaseRoundType;




      ]]>
      </mx:Script>

      <mx:ArrayCollection id="format" />

      <mx:NumberFormatter id="numberFormatter"
      precision="2"
      rounding="up" />




      <mx:VBox paddingTop="10" height="536" width="708">
      <mx:Text paddingLeft="15" text="Default Rate Analyzer" fontSize="14" fontWeight="bold" color="#FFFFFF"/>
      <mx:HBox paddingTop="10" paddingLeft="10">
      <mx:VBox>
      <mx:Panel title="Spread Numbers between Treasuries and Bond type:" height="105">



      <mx:Form id="myForm1" width="350" paddingTop="10" height="65">
      <mx:HBox>
      <mx:HSlider id="mySlider" snapInterval=".01" maximum="30" showDataTip="true" liveDragging="true" width="234" tickInterval="10" borderColor="#66658a" minimum="0" value="16.79" labels="[0%,10%,20%,30%]" visible="true">
      </mx:HSlider>
      <mx:NumericStepper id="stepper" stepSize=".01" value="{mySlider.value}" maximum="3000" minimum="0" minWidth="70" maxWidth="100" includeInLayout="true" toolTip="Increment number by .01%"/>
      </mx:HBox>
      </mx:Form>

      </mx:Panel>
      <mx:Panel title="Risk Premium:" height="117">
      <mx:Form id="myForm2" width="350" height="73" paddingTop="10">
      <mx:HBox height="41">


      <mx:HSlider id="mySlider2" snapInterval=".01" maximum="20" showDataTip="true" liveDragging="true" width="234" tickInterval="5" borderColor="#66658A" minimum="0" values="3.00" labels="[0%,5%,10%,15%,20%]"/>
      <mx:NumericStepper id="stepper2" stepSize=".01" value="{mySlider2.value}" maximum="50" minimum="0" minWidth="70" maxWidth="100" toolTip="Increment number by .01%"/>
      </mx:HBox>
      </mx:Form>
      </mx:Panel>
      <mx:Panel title="Calculate Current Spread (Less Risk Premium):">
      <mx:Form id="myForm3" width="350">
      <mx:FormItem label="Calculate Current Spread: " width="314">
      <mx:Label text="{numberFormatter.format(stepper.value-stepper2.value)+&apos;%&apos;}" selectable="false" maxWidth="150" minWidth="50" width="149" id="inputVal" textAlign="right"/>
      </mx:FormItem>
      </mx:Form>
      </mx:Panel>
      <mx:Panel title="Default Rate Loss:" width="368" height="109">

      <mx:HBox height="69" width="344" id="myForm5" paddingBottom="10" paddingTop="10" paddingLeft="15">

      <mx:HSlider id="mySlider0" snapInterval=".25" maximum="100" showDataTip="true" liveDragging="true" width="234" tickInterval="20" minimum="0" allowTrackClick="true" borderColor="#66658a" values="80.00" labels="[0%,20%,40%,60%,80%,100%]" height="42"/>
      <mx:NumericStepper id="stepper0" stepSize=".01" value="{mySlider0.value}" maximum="100" minimum="0.00" minWidth="70" maxWidth="100" toolTip="Increment number by .01%"/>

      </mx:HBox>


      </mx:Panel>
      </mx:VBox>
      <mx:VBox height="456">
      <mx:Panel title="Results: Calculated Implied Default Rate" width="264" height="106">
      <mx:VBox width="100%">
      <mx:HBox paddingTop="5" width="100%">
      <!-- <mx:FormItem>
      <mx:HBox>
      <mx:Button label="Reset" id="reset_butt" enabled="false" click="reset()" />
      </mx:HBox>

      </mx:FormItem>-->
      </mx:HBox>
      <mx:HBox width="100%" paddingLeft="15">
      <mx:Label text="{numberFormatter.format((stepper.value-stepper2.value)/stepper0.value*(100))}%" maxWidth="120" minWidth="50" id="myLabel" fontWeight="bold" fontSize="18" />
      </mx:HBox>
      </mx:VBox>


      </mx:Panel>


      <mx:Script>
      <![CDATA[
      import mx.controls.Text;
      import mx.containers.Canvas;
      import mx.states.AddChild;
      import mx.collections.ArrayCollection;
      import mx.events.CollectionEvent;

      //Mash code block
      [Bindable]
      public var expenses:ArrayCollection;

      //other vars if any


      private function init():void

      {
      //expenses=new ArrayCollection([{FixedValue:"Default Rate", Profit:15.80, Expenses:stepper.value}]);
      expenses=new ArrayCollection([{FixedValue:"Default Rate", Profit:15.80, Expenses:(stepper.value-stepper2.value)/stepper0.value*(100)}]);


      }



      private function setTitles():void {
      PioChart.title="Default Rate";
      }


      // Calculate function



      ]]></mx:Script>
      <mx:Panel title="Chart" width="264" height="327">

      <mx:ColumnChart id="myChart" dataProvider="{expenses}" showDataTips="true" width="240" height="215" showAllDataTips="false" dataTipMode="multiple">

      <mx:verticalAxis>
      <mx:LinearAxis id="PioChart"/>
      </mx:verticalAxis>
      <mx:horizontalAxis>
      <mx:CategoryAxis title="This is Title Axis"
      categoryField="FixedValue"
      />
      </mx:horizontalAxis>

      <!-- //Display Series for the Chart//-->
      <mx:series>
      <mx:ColumnSeries
      xField="FixedValue"
      yField="Profit"
      displayName="1933 (Great Depression)"
      styleName="FixedValueSeries"
      showDataEffect="{slideIn}"
      />
      <mx:ColumnSeries
      xField="FixedValue"
      yField="Expenses"
      displayName="My Default Rate Value"
      styleName="userValueSeries"
      showDataEffect="{slideIn}"
      />

      </mx:series>
      </mx:ColumnChart>
      <mx:Legend dataProvider="{myChart}"/>

      </mx:Panel>
      </mx:VBox>
      </mx:HBox>
      </mx:VBox>



      <mx:Style>
      .myStyle {
      fontFamily:Verdana;
      fontSize:12;
      color:#4691E1;
      fontWeight:bold;
      fontStyle:italic;
      }
      </mx:Style>

      <mx:Style>
      .FixedValueSeries {
      fontSize:8;
      labelPosition:inside;
      labelAlign:top;
      }

      .userValueSeries {
      fontSize:8;
      labelPosition:inside;
      labelAlign:top;
      }

      </mx:Style>
      <mx:SeriesSlide id="slideIn" duration="1000" direction="up"/>

      </mx:Application>