Flex DateTimeAxis 重复轴标签值

发布于 2024-10-05 13:20:30 字数 1189 浏览 2 评论 0原文

这个简单的代码在水平日期时间轴上的 2 个位置上生成 11 月 7 日:

<mx:Application 
        xmlns:mx="http://www.adobe.com/2006/mxml">

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

            [Bindable]
            public var ac:ArrayCollection = new ArrayCollection(
                [
                    {completions: "11636", date: new Date(2010, 10, 7)}, 
                    {completions: "33060", date: new Date(2010, 10, 8)}, 
                ]);
        ]]>
    </mx:Script>

    <mx:Panel title="Bar Chart">
        <mx:BarChart id="myChart" 
                      dataProvider="{ac}">
            <mx:horizontalAxis>
                <mx:DateTimeAxis dataUnits="days" 
                                 displayLocalTime="true"/>
            </mx:horizontalAxis>
            <mx:series>
                <mx:LineSeries xField="date" yField="completions"/>
            </mx:series>
        </mx:BarChart>
    </mx:Panel>
</mx:Application>

将日期更改为 11 月 8 日和 9 日,一切都很好......

有人知道如何解决此问题吗?

This simple code results in November 7th in 2 places on the horizontal dateTimeAxis:

<mx:Application 
        xmlns:mx="http://www.adobe.com/2006/mxml">

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

            [Bindable]
            public var ac:ArrayCollection = new ArrayCollection(
                [
                    {completions: "11636", date: new Date(2010, 10, 7)}, 
                    {completions: "33060", date: new Date(2010, 10, 8)}, 
                ]);
        ]]>
    </mx:Script>

    <mx:Panel title="Bar Chart">
        <mx:BarChart id="myChart" 
                      dataProvider="{ac}">
            <mx:horizontalAxis>
                <mx:DateTimeAxis dataUnits="days" 
                                 displayLocalTime="true"/>
            </mx:horizontalAxis>
            <mx:series>
                <mx:LineSeries xField="date" yField="completions"/>
            </mx:series>
        </mx:BarChart>
    </mx:Panel>
</mx:Application>

Change the dates to November 8th and 9th and all is good....

Anyone have any ideas how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

但可醉心 2024-10-12 13:20:31

看起来它与 UTC 时间有关,因为这修复了它:

<mx:DateTimeAxis dataUnits="days" displayLocalTime="true" labelFunction="formatDate"/>

public function formatDate(value:Date, prev:Date, axis:IAxis):String
{
    return dateFormatter.format(new Date(value.fullYear, value.month, value.dateUTC));
}

但是,我不想这样做......

It looks like it has something to do with UTC time as this fixes it:

<mx:DateTimeAxis dataUnits="days" displayLocalTime="true" labelFunction="formatDate"/>

public function formatDate(value:Date, prev:Date, axis:IAxis):String
{
    return dateFormatter.format(new Date(value.fullYear, value.month, value.dateUTC));
}

But, I'd rather not do this...

吻风 2024-10-12 13:20:31

首先,好人输入了整个应用程序代码(方便运行)。

复制它并在 Flex Builder 3 中运行它,它给了我两个日期:10/11/7 和 10/11/8。这就是您正在寻找的内容(假设该月份是从零开始的)。一定是地域问题。

这是第一次约会的调试视图,也许可以根据您的查看详细信息(注意时间偏移)

alt text

Firstly, good man for putting in the entire app code (handy for running).

Copied it and ran it in Flex Builder 3, and it gave me the two dates, 11/7/10 and 11/8/10. Which is what you were looking for (given that month is zero based). Must be a locale thing.

Here is a debug view of the first date, maybe check details against yours (note the time offset)

alt text

醉梦枕江山 2024-10-12 13:20:31

布莱恩·毕肖普提到了时区偏移,这让我开始思考。这是一个更简单的应用程序:

<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.events.FlexEvent;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                var d1:Date = new Date(2010, 10, 7);
                var d2:Date = new Date(2010, 10, 8);
                // put breakpoint here...
            }
        ]]>
    </fx:Script>    

</s:Application>

这是我的机器(在丹佛)上的属性(注意 timezoneOffset 属性。我怀疑差异是因为 11/7 是夏令时):

alt text

由于某种原因,带有 displayLocalTime=true 的 datetimeaxis 将 d2.date 转换为 7 而不是 8。

brian bishop mentioned timezone offset, so that got me thinking. here's a simpler app:

<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.events.FlexEvent;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                var d1:Date = new Date(2010, 10, 7);
                var d2:Date = new Date(2010, 10, 8);
                // put breakpoint here...
            }
        ]]>
    </fx:Script>    

</s:Application>

and here's what the properties look like on my machine (in Denver) (note the timezoneOffset property. the difference i suspect is because 11/7 was daylight savings day):

alt text

for some reason, datetimeaxis with displayLocalTime=true, converts d2.date to 7 instead of 8.

以酷 2024-10-12 13:20:31

我在我的应用程序中使用以下函数进行日期比较,而不是使用 new Date(obj) ,它对我有用。您也可以尝试一下!
注意:在我的例子中,“value”参数是一个字符串“02/07/2011”。

private function isoToDate(value:String):Date
        {
            var dateStr:String=value;
            dateStr=dateStr.replace(/\-/g, "/");
            dateStr=dateStr.replace("T", " ");
            dateStr=dateStr.replace("Z", " GMT-0000");
            dateStr=dateStr.substr(0, dateStr.lastIndexOf("/"));
            return new Date(Date.parse(dateStr));
        }

I used the below function for Date comparison in my application instead of having new Date(obj) and it worked for me.You can also give it a try!
Note:'value' param was a String "02/07/2011" in my case.

private function isoToDate(value:String):Date
        {
            var dateStr:String=value;
            dateStr=dateStr.replace(/\-/g, "/");
            dateStr=dateStr.replace("T", " ");
            dateStr=dateStr.replace("Z", " GMT-0000");
            dateStr=dateStr.substr(0, dateStr.lastIndexOf("/"));
            return new Date(Date.parse(dateStr));
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文