3 Replies Latest reply on Sep 11, 2007 12:33 AM by z00plankton

    Adding series to a chart at run time

      I want the user to be able to select several different sensor feeds in a monitoring application, when they click a certain button I want it to add a line series on the chart and load data and display it....
      what is the best way to do this? There may be an arbitrary number of feeds so I don't really want to make a bunch of empty arrays and series... unless it's totally necessary.
        • 1. Re: Adding series to a chart at run time
          saliksyed Level 1
          Furthermore I also want to add more components at run time...
          For instance for each line series I add, I need to add a checkbox at the bottom , when the user checks that box it should display the line, and when un checked it will hide it.
          can I create and add such components at run time?
          • 2. Re: Adding series to a chart at run time
            Hi -

            You can certainly add line series to a chart :

            <mx:LineChart id="mainChart">

            then at runtime, do something like this :

            var ChartSeries:Array = mainChart.series;
            var newSeries:LineSeries = new LineSeries();
            newSeries.yField = ... ;
            newSeries.dataProvider = ... ;
            newSeries.displayName = ... ;
            mainChart.series = ChartSeries;

            I'm sure you can add checkboxes etc at runtime too, but I've not done that, so hopefully someone else with help out there.


            • 3. Re: Adding series to a chart at run time
              Just a note on John's example... just be aware that any effects you might want to happen (ie.showDataEffect, hideDataEffect) will not trigger. I think this is cause a new instance of the series (new LineSeries()) is created,

              What works for me though is if you 'recycle' the series by re-assigning the dataprovider, the effects do happen. Itsa bit long-winded but yeah...