0 Replies Latest reply on Mar 7, 2008 12:25 PM by ybjames

    Problem changing chart after initial render

    ybjames
      I am having trouble changing chart parameters in a method called using "creationComplete". In particular, I am trying to set the maximum value on a vertical axis in an init() method and it is not working correctly.

      Consider the simple stacked chart given by the mxml file below:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
      <mx:Script><![CDATA[
      import mx.collections.ArrayCollection;

      [Bindable]
      public var sentiment:ArrayCollection = new ArrayCollection( [
      {date: "20080227", neutral: "23", positive: "23", negative: "8"}, {date: "20080228", neutral: "27", positive: "20", negative: "14"}, {date: "20080229",neutral: "16",positive:"5",negative: "15"}
      ]);

      public function myParseFunction(s:String):Date {

      // Create the new Date object. Subtract one from
      // the month property because months are zero-based in
      // the Date constructor.
      var year:String = s.substr(0,4);
      var month = Number(s.substr(4,2)) - 1 ;
      var day = s.substr(6,2);
      var newDate:Date = new Date(year, month, day);

      return newDate;
      }

      public function init():void {
      //v1.maximum = 61;
      }

      ]]></mx:Script>

      <mx:Panel title="Sentiment Chart" width="640" height="480">
      <mx:Legend dataProvider="{myChart}" direction="horizontal"/>
      <mx:ColumnChart id="myChart" showDataTips="true" height="100%" width="100%" dataProvider="{sentiment}">
      <mx:horizontalAxis>

      <mx:DateTimeAxis id="h1" dataUnits="days" labelUnits = "days" displayLocalTime="true" parseFunction="myParseFunction"/>

      </mx:horizontalAxis>

      <mx:horizontalAxisRenderers>
      <mx:AxisRenderer placement="bottom" axis="{h1}"/>
      </mx:horizontalAxisRenderers>

      <mx:verticalAxisRenderers>
      <mx:AxisRenderer placement="left" axis="{v1}"/>

      </mx:verticalAxisRenderers>

      <mx:series>
      <mx:ColumnSet type="stacked">

      <mx:ColumnSeries id="negSeries" horizontalAxis="{h1}" dataProvider="{sentiment}" displayName="neg" xField = "date" yField="negative">
      <mx:verticalAxis>
      <mx:LinearAxis id="v1" minimum="0" maximum="61"/>
      </mx:verticalAxis>
      </mx:ColumnSeries>
      <mx:ColumnSeries horizontalAxis="{h1}"
      dataProvider="{sentiment}" verticalAxis="{v1}" displayName="neutral" xField = "date" yField="neutral"/>
      <mx:ColumnSeries horizontalAxis="{h1}"
      dataProvider="{sentiment}" verticalAxis="{v1}" displayName="pos" xField = "date" yField="positive"/>

      </mx:ColumnSet>

      </mx:series>
      </mx:ColumnChart>
      </mx:Panel>
      </mx:Application>

      This renders correctly if I leave the statement v1.maximum = 61 (in the init() method) commented out, but uncommenting this line results in the columns shrinking down. The columns no longer line up with the correct vertical hash values (even though their tooltips show correct values).

      Any help would be greatly appreciated.

      Thanks,

      James