2 Replies Latest reply on Apr 1, 2010 10:05 AM by Cr99

    Disabling series in charts

    Cr99 Level 1

      My app generates charts from data generated by various machines and scanners.  Sometimes there are a lot of these signals and excessive noise so the chart needs to be able to "turn off" some of the data sometimes.  I can do that fairly easily with this code:


      // myLegend is the chart legend

      myLegend.addEventListener(MouseEvent.CLICK, toggleSeries);


      public function toggleSeries(e:MouseEvent):void {

                  var item:LegendItem = e.target as LegendItem;

                  if (item == null) return;

                  var series:Series = item.element as Series;

                  var enabled:Boolean = series.visible;

                  series.visible = !enabled;

                  // turn label "off" by making it gray

                  if (!series.visible) item.setStyle("color", 0xCCCCCC);

                  else item.setStyle("color", 0x000000);



      However, what I also need the chart to do is to resize it's vertical axes.  When I give the chart new data, it does this automatically, but apparently setting a series to no longer be visible does not trigger this behavior.  How can I do this?

        • 1. Re: Disabling series in charts
          matthew horn Level 3

          By setting the series' visibility, you're not really removing it from the chart, you're just hiding it. to have the axes redraw, you should remove the series from the chart. You do this by resetting the value of the series property.

          • 2. Re: Disabling series in charts
            Cr99 Level 1

            Thanks for the advice.  The problem is, I can't just remove the series because I want to give the user the option to toggle it back on later.  But I've found that if I simply erase the data from the series dataProvider, the chart will redraw as I wish:


            if (!series.visible) {

                        series.dataProvider = new ArrayCollection();

                        item.setStyle("color", 0xCCCCCC);



            The problem I now have is how to get the data back.  I do have it stored in another variable, but to find it, I need to know both the name of the series and the color (because in some of the charts two or more series actually have the same name).  So now I am having problems getting the color value, but I'll post that in another thread since it's a different topic really.