1 Reply Latest reply on Feb 23, 2010 2:42 PM by Gregory Lafrance

    verticalAxisRenderer vs verticalAxisRenderers

    Travis Dudley

        I have an application where I am dynamically adding (and removing) vertical axis to a LineChart. My problem is that when the chart is first created, I may not have any data to load. This causes the line chart to create a default vertical axis renderer in the verticalAxisRenderer property (which I though was now depricated). I have tried to set this property to null to get rid of it, but that gives me an error. The following is a dummy program to show what I am trying to accomplish. Any help with this would be much appreciated.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">

       

          <mx:Script>
      <![CDATA[
          import mx.core.ContainerCreationPolicy;
          import mx.charts.AxisRenderer;
          import mx.charts.series.LineSeries;
          import mx.events.FlexEvent;
              private function init():void{
                  creationPolicy = ContainerCreationPolicy.ALL;
                  addAxis.addEventListener(FlexEvent.BUTTON_DOWN, addY);
              }
             
              private function addY(ev:FlexEvent):void{
                  //I added this label just so I could verify that the verticalAxisRenderer property was, in fact, being set.
                  dflt.text = chart.verticalAxisRenderer == null ? "None": "Something";
                 
                  //Making sure that the verticalAxisRenderers Array started empty, and then grew properly.
                  addAxis.label = "Add "+chart.verticalAxisRenderers.length;
                 
                  //Add a new empty series and renderer
                  var ls:LineSeries = new LineSeries();
                  var ar:AxisRenderer = new AxisRenderer();
                  ar.axis = vax;
                  chart.series = chart.series.concat(ls);
                  chart.verticalAxisRenderers = chart.verticalAxisRenderers.concat(ar);
                 
                  //This was my attempt to clear the default renderer.
      //            if(chart.verticalAxisRenderer != null){
      //                chart.verticalAxisRenderer = null;
      //            }
              }   
      ]]>
          </mx:Script>

       

              <mx:Canvas id="chartCanvas" label="Chart">
                  <mx:LineChart id="chart" clipContent="true">
                      <mx:horizontalAxis>
                          <mx:DateTimeAxis id="timeAxis" dataUnits="minutes"/>
                      </mx:horizontalAxis>
                      <mx:horizontalAxisRenderer>
                          <mx:AxisRenderer color="0x000000"/>
                      </mx:horizontalAxisRenderer>
                     
                      <mx:verticalAxis>
                          <mx:LinearAxis id="vax"/>
                      </mx:verticalAxis>               
                      
                  </mx:LineChart>
                  <mx:Label id="dflt" x="456" y="30" text="verticalAxisRenderer"/>
                  <mx:Button x="456" y="0" label="Add" id="addAxis"/>
              </mx:Canvas>
         
      </mx:Application>

        • 1. Re: verticalAxisRenderer vs verticalAxisRenderers
          Gregory Lafrance Level 6

          This seems to fix the problem.

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
           
              <mx:Script>
          <![CDATA[
              import mx.core.ContainerCreationPolicy;
              import mx.charts.AxisRenderer;
              import mx.charts.series.LineSeries;
              import mx.events.FlexEvent;
                  private function init():void{
                      creationPolicy = ContainerCreationPolicy.ALL;
                      addAxis.addEventListener(FlexEvent.BUTTON_DOWN, addY);
                  }
                  
                  private function addY(ev:FlexEvent):void{
                      //I added this label just so I could verify that the verticalAxisRenderer property was, in fact, being set.
                      dflt.text = chart.verticalAxisRenderers == null ? "None": "Something";
                      
                      //Making sure that the verticalAxisRenderers Array started empty, and then grew properly.
                      addAxis.label = "Add "+chart.verticalAxisRenderers.length;
                      
                      //Add a new empty series and renderer
                      var ls:LineSeries = new LineSeries();
                      var ar:AxisRenderer = new AxisRenderer();
                      ar.axis = vax;
                      chart.series = chart.series.concat(ls);
                      chart.verticalAxisRenderers = chart.verticalAxisRenderers.concat(ar);
                      
                      //This was my attempt to clear the default renderer.
                      if(chart.verticalAxisRenderers != null){
                          chart.verticalAxisRenderers = new Array();
                      }
                  }    
          ]]>
              </mx:Script>
           
                  <mx:Canvas id="chartCanvas" label="Chart">
                      <mx:LineChart id="chart" clipContent="true">
                          <mx:horizontalAxis>
                              <mx:DateTimeAxis id="timeAxis" dataUnits="minutes"/>
                          </mx:horizontalAxis>
                          <mx:horizontalAxisRenderer>
                              <mx:AxisRenderer color="0x000000"/>
                          </mx:horizontalAxisRenderer>
                          
                          <mx:verticalAxis>
                              <mx:LinearAxis id="vax"/>
                          </mx:verticalAxis>                
                           
                      </mx:LineChart>
                      <mx:Label id="dflt" x="456" y="30" text="verticalAxisRenderer"/>
                      <mx:Button x="456" y="0" label="Add" id="addAxis"/>
                  </mx:Canvas>
              
          </mx:Application>