4 Replies Latest reply on Apr 14, 2007 3:28 AM by Arthur@aginova

    DYNAMIC CREATION OF LINE SERIES USING ACTIONSCRIPT

    Arthur@aginova
      There's something wierd about flex or im doing something wrong?
      - when i create a line series manually using mxml and specify a id for the series, it works.
      - similarly when i try to dynamically create a line series using actionscript & define an "id" property, flex does not understand! what am i doing wrong?
      code for reference:

      private function addSeries(series:Array, yField:String,id:String) // addseries(series,"date","1000")
      var ls:LineSeries= new LineSeries();
      var stroke:Stroke = new Stroke()
      ls.yField = yField;
      ls.xField="ts"
      ls.dataProvider=dp
      ls.id=id // tried defining it dynamically, but flex does not find
      this.mychart.series.push(ls)

      THIS IS THE ERROR I GET : "TypeError: Error #1010: A term is undefined and has no properties."
        • 1. Re: DYNAMIC CREATION OF LINE SERIES USING ACTIONSCRIPT
          babo_ya Level 3
          ?
          Not sure what you are trying to do but, since you created an object of LineSeries using .... var Is:LineSeries = new LineSeries(); so the id is 'Is"...
          • 2. Re: DYNAMIC CREATION OF LINE SERIES USING ACTIONSCRIPT
            Arthur@aginova Level 1
            i know "LS" is the variable name for the line series definition, how can that be the id for all the line series ?
            anyways i hope im able to explain what i want : ?
            i wud be dynamically showing / hiding the line series, hence visible property would work on the bases of different ids is that correct?
            i want to define an id for each line series
            eg. lineseries[0].id="a1"
            lineseries[1].id="a2"
            in mxml:

            i define it like this :
            <mx:Lineseries id="a1" visible="true" dataProvider="{whatever}" />
            <mx:Lineseries id="a2" visible="false" dataProvider="{whatever}"/>
            how do i do this in actionscript? hope this explains! check what i have tried in my earlier post
            • 3. DYNAMIC CREATION OF LINE SERIES USING ACTIONSCRIPT
              babo_ya Level 3
              I see... I played around with the line chart ...
              Hopefully this helps... if not forgive me...
              I know why you are trying to use the id property which i agree doesn't work.
              since the series is an array in your lineChart use the index to set the visible property false/true.
              lineChart.series[0].visible = true/false;

              <mx:Lineseries id="a1" visible="true" dataProvider="{whatever}" />
              <mx:Lineseries id="a2" visible="false" dataProvider="{whatever}"/>

              create a function called init();

              public function init():void
              {
              var lineS1:LineSeries = new LineSeries();
              lineS1.visible = true/false;
              lineChart.series.push(lineS1);

              var lineS2:LineSeries = new LineSeries();
              lineS2.visible = true/false;
              lineChart.series.push(lineS2);
              }
              ... and the key is to call this init function on initialize event...NOT on createComplete event
              <mx:LineChart.... initialize="init()" .... />

              and to show both lines... call this function...

              public function showLines():void
              {
              lineChart.series[0].visible = true;
              lineChart.series[1].visible = true;
              }

              Hope this helps....








              • 4. Re: DYNAMIC CREATION OF LINE SERIES USING ACTIONSCRIPT
                Arthur@aginova Level 1
                Hi Babo_Ya,

                thanks, your chart initialize function helped me in some way.
                another problem is when i use the legend it does not show the legend marks for the dynamic series created.
                Any Idea!