5 Replies Latest reply on Feb 21, 2007 6:29 AM by Oddsy

    Flex Chart Data Range Problem

    rexralph
      The following is the mxml I have made.
      When the minimum and maximum are not set, it will show the line series properly.
      But when I set the min and max for date time axis to
      dt1.minimum=new Date("2005","7","30");
      dt1.maximum=new Date("2005","8","3");

      Then the line from data point "{date: "2005, 7, 29", close: 42.11}" to "{date: "2005, 8, 1", close: 42.71}" is not being displayed.
      I under stand that the data point "{date: "2005, 7, 29", close: 42.11}" is outside the range of {"2005","7","30"}. But I would like to have the line to be shown on chart by interpolating the data from previous data point.

      Can some one please show me some light on achieving this?

      Thanks in advance.



      <?xml version="1.0"?>
      <!-- Simple example to demonstrate the DateTimeAxis class. -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="settings();">

      <mx:Script>
      <![CDATA[

      import mx.collections.ArrayCollection;

      [Bindable]
      public var stockDataAC:ArrayCollection = new ArrayCollection( [
      {date: "2005, 7, 27", close: 41.71},
      {date: "2005, 7, 28", close: 42.21},
      {date: "2005, 7, 29", close: 42.11},
      {date: "2005, 8, 1", close: 42.71},
      {date: "2005, 8, 2", close: 42.99},
      {date: "2005, 8, 3", close: 44} ]);

      public function settings():void
      {
      dt1.minimum=new Date("2005","6","30");
      dt1.maximum=new Date("2005","7","3");
      }

      public function myParseFunction(s:String):Date {
      // Get an array of Strings from the comma-separated String passed in.
      var a:Array = s.split(",");
      // Create the new Date object. Subtract one from the month property.
      // The month property is zero-based in the Date constructor.
      var newDate:Date = new Date(a[0],a[1]-1,a[2]);
      return newDate;
      }
      ]]>
      </mx:Script>

      <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 id="dt1" dataUnits="days" parseFunction="myParseFunction" />
      </mx:horizontalAxis>

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

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

      </mx:Panel>
      </mx:Application>
        • 1. Re: Flex Chart Data Range Problem
          Oddsy
          Set the series' filterData property to false.

          However, there's a bug in the framework that means if you have filterData set to false and, for example, set the minimum or maximum of an axis the series will no longer provide any hitData (i.e. will appear to be non-interactive). There's a workaround though so all is not lost. And if you don't need hitData from the series then it's no problem at all.
          • 2. Re: Flex Chart Data Range Problem
            rexralph Level 1
            Thanks a lot.

            I do need hitData together with filterData for events processing. Can you please tell the work around?
            • 3. Re: Flex Chart Data Range Problem
              Oddsy Level 1
              By the way, using filterData = false results in slightly slower rendering because it is doing the computations required for all the points rather than just those in the axes ranges. An halfway-house solution might be to use filterData = false combined with manual filtering of the data provider to ensure you are just getting it to render a smaller portion of the data.

              Anyway, the workaround. You'll have to have a poke around in the LineSeries source code to fully understand what I'm saying here. You need to extend the LineSeries class and extend the findDataPoints function. In the LineSeries' findDataPoints function the if (!isNaN(v.yFilter) && !isNaN(v.xFilter)) condition will fail because when filterData = false and the filterCache function of the series is called (this happens when the min or max of an axis is set because the mapping changes) the .yFilter and xFilter properties will be NaN. That makes sense in it's own way, but the upshot of that is that the minItem variable is never set and, therefore, an empty array will always be returned.

              So the fix is to copy the code from the LineSeries source code and in your overriding function change the if (!isNaN(v.yFilter) && !isNaN(v.xFilter)) condition to if (!isNaN(v.yNumber) && !isNaN(v.xNumber)). Before you do that though, check that your y/xFilter and y/xNumber properties do represent the same value. So yes, this is a nasty little hack but I haven't found any other way to solve the problem.
              • 4. Re: Flex Chart Data Range Problem
                rexralph Level 1
                Thank you very much. I could get the dataTips and hitData now by using the extended class of LineSeries.

                However I could not understand your comment "Before you do that though, check that your y/xFilter and y/xNumber properties do represent the same value. ".

                • 5. Re: Flex Chart Data Range Problem
                  Oddsy Level 1
                  Ignore it, I was confusing this workaround with some other work (something surprisingly similar) I have been doing.

                  Glad it's sorted your problem too.