2 Replies Latest reply on Jul 9, 2013 5:19 AM by support & learning

    Null reference error in axis renderer when redrawing chart

    dah328
      I have a charting application that allows a user to manipulate the underlying dataset and have the chart redrawn at will. I am recreating the chart series, axes, and axis renderers on the fly and reapplying them to the chart in my application. I have recently started getting a null object reference in the AxisRenderer.updateDisplayList() method on line 1128. It seems that the AxisRenderer object is in a weird state because its reference to its parent chart is null. I do not know how that could be the case unless I am doing something wrong in my programmatic creation of my charts axes and axis renderers. Currently, I am doing something similar to this:


      var colSeries : ColumnSeries = new ColumnSeries():
      var axis : LinearAxis = new LinearAxis();

      // create axis renderer
      var ar1 : AxisRenderer = new AxisRenderer();
      ar1.placement = "left";
      ar1.axis = axis;
      colSeries.verticalAxis = axis;

      var seriesAr : Array = { colSeries };
      chart.series = seriesAr;
      chart.verticalAxisRenderer = ar1;

      Is there anything I am leaving out. I tried setting the parent property on the AxisRenderer instance but it is a readonly property.

      Dan
        • 1. Re: Null reference error in axis renderer when redrawing chart
          Cr99 Level 1

          I'm getting this same error when I try to reuse an AxisRenderer or for that matter when I try to reuse a chart. The app needs to run 24/7 and so I need to keep the app from bloating and using so much memory because if I just let it run normally it eventually crashes because AIR never seems to garbage collect the unused components after I remove all the children from the container and redraw the fresh chart.

           

          Here's a few snippets to show what I'm doing.  It works fine the first time through but after that it crashes giving me this error:

           

           

          TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at mx.charts::AxisRenderer/updateDisplayList()[C:\Work\flex\dmv_automation\projects\datavisu alisation\src\mx\charts\AxisRenderer.as:1128]

           

          (by the way, here is the relavant code from AxisRenderer line 1128 where the error is occurring)

           

          var chart:ChartBase = this.chart;

           

          if (_bGuttersAdjusted == true &&

                      chart.chartState != ChartState.PREPARING_TO_HIDE_DATA &&

                      chart.chartState != ChartState.HIDING_DATA)

           

          so it seems like reference to chart is getting set to null somehow, though I have no idea about the inner workings of AxisRenderer which could be causing this

           

          // here's some samples from my code

           

          var genericChart:CartesianChart = getCartesianChart();

          var renderers:ArrayCollection = new ArrayCollection();

           

          // horizontal axis

           

          var ar:AxisRenderer = getAxisRenderer();

          var hAxis:DateTimeAxis = getDateTimeAxis();

          ar.axis = hAxis;

          ar.setStyle("canDropLabels", "true");

          genericChart.horizontalAxisRenderers = [ar];

          genericChart.horizontalAxis = hAxis;

           

          // vertical axis

           

          var vAxis:LinearAxis = getLinearAxis();

          vAxis.baseAtZero = false;

          var axr:AxisRenderer = getAxisRenderer();

          axr.axis = vAxis;

          axr.setStyle("canDropLabels", "true");

          // -- code which follows (not shown) adds series, stokes, and other visual elements ...

          genericChart.verticalAxisRenderers = renderers.toArray();

           

           

           

           

          // related function gets a renderer from pool rather than making a new

          // renderer each time to try to conserve memory

          // the index rendererIndex gets set to zero each time a new set of charts

          // gets drawn

           

          public function getAxisRenderer():AxisRenderer {

                 if (rendererIndex >= rendererArray.length) {

                      var renderer:AxisRenderer = new AxisRenderer();

                      rendererArray.addItem(renderer);

                      rendererIndex++;

                      return renderer;

                 }

                 var rend:AxisRenderer = rendererArray.getItemAt(rendererIndex) as AxisRenderer;

                 rendererIndex++;

                 return rend;

          }

           

           

          // I have almost identical methods used for memory management for the genericChart, hAxis, vAxis, etc.

           

           

          public function getCartesianChart():CartesianChart { // code not shown }

          public function getDateTimeAxis():DateTimeAxis { // code not shown }

          public function getLinearAxis():LinearAxis { // code not shown }

          • 2. Re: Null reference error in axis renderer when redrawing chart
            support & learning

            May i know the solution to overcome the above issue which is urgent, for first time i am getting the same error and my application gets hang.