English 中文(简体)
Why does flex DateTimeAxis creates duplicate months on the axis?
原标题:

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

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

问题回答

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,





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签