2 Replies Latest reply on Jun 23, 2006 8:55 PM by poonamsheth

    Line Chart : How to specify a time X axis?

    FredFlex
      Hello,

      I want to use Line Chart to show 2 series :

      Serie 1:
      {time : "2006-05-25 12:00:01", p1 : 45}
      {time : "2006-05-25 13:00:01", p1 : 34}
      {time : "2006-05-25 13:05:01", p1 : 78}

      Serie 2:
      {time : "2006-05-25 12:10:01", p1 :80}
      {time : "2006-05-25 12:50:01", p1 : 56}
      {time : "2006-05-25 13:00:01", p1 : 88}

      The big problem is that when I show the chart, the x axis is not linear (I would like something like 12:00:00, 12:15:00, etc... one mark each 15 minutes with sample at the right place). How to do?

      Thank for help me

      FredFlex
        • 1. Re: Line Chart : How to specify a time X axis?
          FredFlex Level 1
          Finally I found:

          I must use DateTimeAxis class
          • 2. Re: Line Chart : How to specify a time X axis?
            poonamsheth Level 1
            Data points on the DateTimeAxis support the String, Number, or Date data types.

            1] Date: If the value of the data point is an instance of a Date object, it already represents an absolute datetime value and needs no interpretation. It is possible to pass a Date object as a data value if you use the parseFunction property of the 2] DateTimeAxis. That function returns a Date object. For more information, see Using parseFunction.
            3] String: You can use any format that the Date.parse() method supports. The supported formats are:
            4] Day Month Date Hours:Minutes:Seconds GMT Year (for example, "Tue Feb 1 12:00:00 GMT-0800 2005")
            5] Day Month Date Year Hours:Minutes:Seconds AM|PM (for example, "Tue Feb 1 2005 12:00:00 AM")
            6] Day Month Date Year (for example, "Tue Feb 1 2005")
            7] Month/Day/Year (for example, "02/01/2005")
            8] Month/Year (for example, "02/01/2005")
            You can also write custom logic that takes any string and returns a date using the parseFunction property of the DateTimeAxis.
            9] Number: If you use a number, it is assumed to be the number of milliseconds since Midnight, 1/1/1970. For example, 543387600000. To get this value on an existing Date object, use the Date object's getTime() method.
            The following example uses a string value for the date that matches the MM/DD/YYYY format and specifies that the


            the example uses a string value and parseFunction:
            ------------------------------------------------------------------------
            the parseFunction property of the DateTimeAxis tag to customize the value of the data points. With this method, you specify a method that accepts a String and returns a Date object.

            The following example shows a parse function that creates a new Date object out of strings in the data provider that match the "YYYY, MM, DD" pattern:


            <mx:Script><![CDATA[
            [Bindable]
            public var aapl:Array = [
            {date: "2005, 8, 1", close: 42.71},
            {date: "2005, 8, 2", close: 42.99},
            {date: "2005, 8, 3", close: 44}
            ];

            public function myParseFunction(s:String):Date {
            // Get an array of Strings from the comma-separated String passed in.
            var a:Array = s.split(",");
            trace("y: " + a[0]);
            trace("m: " + a[1]);
            trace("d: " + a[2]);
            // Create the new Date object.
            var newDate:Date = new Date(a[0],a[1],a[2]);
            return newDate;
            }
            ]]></mx:Script>
            <mx:LineChart id="mychart" dataProvider="{aapla}" showDataTips="true">
            <mx:horizontalAxis>
            <mx:DateTimeAxis dataUnits="days" parseFunction="myParseFunction"/>
            </mx:horizontalAxis>
            <mx:series>
            <mx:Array>
            <mx:LineSeries yField="close" xField="date" displayName="AAPL"/>
            </mx:Array>
            </mx:series>
            </mx:LineChart>