tags:

views:

814

answers:

1

I am working with a Flex DateTimeAxis. I have a scenario where the DateTimeAxis sometimes creates duplicate months on the Axis. The month label unit is generated based on a min/max value that is supplied to the DateTimeAxis, it is NOT generated by the series data as far as I can tell. In other words, the duplication does not exist within the data supplied to the chart, but is part of automatic label generation process that DateTimeAxis will execute when supplying a min/max value for the axis.

I have included a simplified example of this issue below. Any help is appreciated.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;

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

        [Bindable] 
        public var stockDataAC:ArrayCollection = new ArrayCollection( [
            {date: new Date(2009,4), close: 41.71},
            {date: new Date(2009,5),close: 42.21},
            {date: new Date(2009,6), close: 42.11},
            {date: new Date(2009,7), close: 42.71},
            {date: new Date(2009,9), close: 42.99}
            ]);

        [Bindable] private var min:Date = new Date(2009,4);
        [Bindable]  private var max:Date = new Date(2010,3);

        private function formatDate(value:Date,previousValue:Date,axis:DateTimeAxis):String {               
      var dateLabel:String = df.format(value);

   return dateLabel;
  }
    ]]>
</mx:Script>

<mx:DateFormatter id="df" formatString="MMM YY"/>
<mx:Panel title="DateTimeAxis Example" height="100%" width="100%">

    <mx:LineChart id="mychart" height="100%" width="100%"
        paddingRight="5" paddingLeft="5" 
        showDataTips="true" dataProvider="{stockDataAC}">

        <mx:horizontalAxis>
            <mx:DateTimeAxis dataUnits="months" labelUnits="months" alignLabelsToUnits="false" labelFunction="formatDate" minimum="{min}" maximum="{max}"/>
        </mx:horizontalAxis>

        <mx:verticalAxis>
            <mx:LinearAxis baseAtZero="false" />
        </mx:verticalAxis>

        <mx:series>
            <mx:LineSeries yField="close" xField="date" displayName="AAPL"/>
        </mx:series>
    </mx:LineChart>

</mx:Panel>

+1  A: 

The problem seems to be in the formatDate function.

Try this:

private function formatDate(value:Date,previousValue:Date,axis:DateTimeAxis):String 
    {   
        trace("Current Value: " + value);            
        trace("Previous Value: " +previousValue);   
        trace("****");         
     var dateLabel:String = df.format(value);
        return dateLabel;
    }

And you will be able to see in the output that the dates by some reason have a different GMT which is causing the problem with the formatting:

Current Value: Sun Nov 1 00:00:00 GMT-0400 2009
Previous Value: Thu Oct 1 00:00:00 GMT-0400 2009
****
Current Value: Mon Nov 30 23:00:00 GMT-0500 2009
Previous Value: Sun Nov 1 00:00:00 GMT-0400 2009
****

Hope this helps,

calderas