2 Replies Latest reply on Jan 26, 2011 7:29 AM by Andrei Kouzmenkov

    SDK 4 Charts bug: DateTimeAxis and AxisRenderer

    Kazaak549879 Level 1

      It looks like the problem was always their since SDK 4.0. Nobody noticed that before?

       

      A Chart (LineChart, AreaChart) throws an exception when it uses DateTimeAxis (on horizontal axis) and dropping of labels is allowed.

      Here is a small Flex 4 program to reproduce the problem:

       

      <?xml version="1.0" encoding="utf-8"?>
      <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="onCreationComplete()">
          <fx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                 
                  [Bindable]
                  private var dgd:ArrayCollection = new ArrayCollection();
                 
                  protected function onCreationComplete():void {
                      for (var i:int = 1; i < 30; i++) {
                          dgd.addItem({ d: new Date(2011, 1, i), v:i + 5 - Math.random()* 10});
                      }
                  }           
              ]]>
          </fx:Script>
         
          <mx:LineChart dataProvider="{dgd}" width="300" height="200">
              <mx:horizontalAxis>
                  <mx:DateTimeAxis id="hx" labelUnits="days" />
              </mx:horizontalAxis>       
              <mx:horizontalAxisRenderers>
                  <!--
                  to fix the problem set canDropLabels="false"
                  -->
                  <mx:AxisRenderer axis="{hx}" canDropLabels="true"/>
              </mx:horizontalAxisRenderers>       
              <mx:series>
                  <mx:LineSeries yField="v" xField="d"/>
              </mx:series>
          </mx:LineChart>   
      </s:Application>

       

      Under SDK 4.1 and SDK 4.5 Hero (October 2010 release) the same exception gets thrown:

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at mx.charts::AxisRenderer/measureHorizontalGutters()[E:\dev\4.x\frameworks\projects\datavis ualization\src\mx\charts\AxisRenderer.as:2277]
          at mx.charts::AxisRenderer/calcRotationAndSpacing()[E:\dev\4.x\frameworks\projects\datavisua lization\src\mx\charts\AxisRenderer.as:1891]
          at mx.charts::AxisRenderer/adjustGutters()[E:\dev\4.x\frameworks\projects\datavisualization\ src\mx\charts\AxisRenderer.as:1567]
          at mx.charts.chartClasses::CartesianChart/updateAxisLayout()[E:\dev\4.x\frameworks\projects\ datavisualization\src\mx\charts\chartClasses\CartesianChart.as:2264]
          at mx.charts.chartClasses::CartesianChart/updateDisplayList()[E:\dev\4.x\frameworks\projects \datavisualization\src\mx\charts\chartClasses\CartesianChart.as:1391]
          at mx.core::UIComponent/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\m x\core\UIComponent.as:8709]
          at mx.managers::LayoutManager/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework \src\mx\managers\LayoutManager.as:663]
          at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framewo rk\src\mx\managers\LayoutManager.as:718]
          at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects \framework\src\mx\managers\LayoutManager.as:1072]

       

      Make sure the chart has explicit sizes, as sometimes removing them eliminates the exception, but not always.

       

      Some ideas of why the error is happening are here: http://forums.adobe.com/message/3403273#3403273

       

      To fix the problem set canDropLabels to "false". Unfortunately then the Chart tries to squeeze all labels, reducing label's font size to unreadable (see the picture):

      screen_0048.jpg

      Is that a bug indeed? Any workaround?

       

      Thanks, Andrei.