2 Replies Latest reply on Jan 18, 2011 4:53 AM by nikos101

    Labels on DateTimeAxis Display in Reverse Data Order

    BaliHi

      Hi ,

       

      If anybody can show me what I am doing wrong here it would be much appreciated but I think its a bug.

       

      I have a line chart with a DateTimeAxis on the x axis and stock prices on the y axis. The observations for each series are separated by one month.

       

      When I display the chart it shows the labels on the x axis in reverse order (time going backwards), even though it displays the chart data in the correct order. I have tried using a labelFunction but cant get it to display correctly as long as the x axis is month based (labelUnits="months" on the DateTimeAxis). Even stranger is if you have labelUnits="years" or any other labelUnits it displays the labels in the correct order.

       

      Anyone who can solve this is a champion.

       

      Here is the code for the chart:

       

      <?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"

      minWidth="

      955" minHeight="600"

      creationComplete="application1_creationCompleteHandler(event)"

      >

       

      <fx:Script>

      <![CDATA[

       

      import mx.charts.series.LineSeries;

       

      import mx.collections.ArrayCollection;

       

      import mx.events.FlexEvent;

       

      [

      Bindable]

       

      public var data:ArrayCollection = new ArrayCollection();

      [

      Bindable]

       

      public var chartData:Array = new Array();

       

       

       

      protected function application1_creationCompleteHandler(event:FlexEvent):void

      {

       

      // TODO Auto-generated method stub

      CreateData(0.05, 0.10);

      }

       

       

      private function CreateData(incA:Number, incB:Number):void{

       

      var startYear:int = 2008;

       

      var startMonth:int = 0;

       

      var startAmount:Number = 1;

       

      var itemNum:int = 0;

       

      for(var j:int=0; j<2; j++)

      {

       

      for(var i:int=0; i<12; i++)

      {

       

      var date:Date = new Date(startYear+j, startMonth+i, 0,0,0,0,0);

       

      var stockPrice:Object = new Object();

      stockPrice.ObsDate = date;

      stockPrice.AmountA = startAmount + (itemNum*incA);

      stockPrice.AmountB = startAmount + (itemNum*incB);

      data.addItem(stockPrice);

      itemNum++;

      }

      }

      }

      ]]>

       

      </fx:Script>

       

      <mx:LineChart id="linechart1" width="100%" height="100%" dataProvider="{data}" >

       

      <mx:series>

       

      <mx:LineSeries yField="AmountA" xField="ObsDate"/>

       

      <mx:LineSeries yField="AmountB" xField="ObsDate"/>

       

      </mx:series>

       

      <mx:verticalAxis>

       

      <mx:LinearAxis id="v1" title="Stock Price"/>

       

      </mx:verticalAxis>

       

      <mx:horizontalAxis>

       

      <mx:DateTimeAxis id="h1" title="Date" labelUnits="months" />

      <mx:DateTimeAxis id="h1" title="Date" labelUnits="months" />

       

       

       

      </mx:horizontalAxis>

       

      </mx:LineChart>

      </s:Application>

       

       

      </mx:horizontalAxis>

       

      </mx:LineChart>

      </s:Application>

       

      </mx:horizontalAxis>

       

      </mx:LineChart>

      </s:Application>