6 Replies Latest reply on Sep 12, 2008 1:15 AM by nikos101

    How do you clear the data on a chart?

    nikos101 Level 2
      How do you clear the data on a chart? Doing

      ratingsChart.dataProvider=null;
      ratingsChart.initialize();

      Doesn't work
        • 1. Re: How do you clear the data on a chart?
          michel_v Level 1
          this works:
          chart.dataProvider = myData; // myData is an arrayCollection
          .
          .
          .
          myData.removeAll();



          • 2. Re: How do you clear the data on a chart?
            EvolvedDSM Level 2
            Sigh, this is something that has needed to change in Flex for a while now. There's one way I've used when needing to reset data on my charts and it's the only way I've seen that works. Try this:

            1) Set an arrayCollection to your data (for example,name it myDataAC).
            2) Create another arrayCollection and set it to the arrayCollection that is holding your data, ex: private var ac:ArrayCollection = myDataAC;
            3) Set your chart's dataProvider to {ac}
            4) Create a button or an object that will call your chart data reset. Set its click property to a function that will reset the data, ex: resetData()
            5) In your script, create a new function called resetData() and insert this code inside it:
            if(ac == myDataAC){
            ac = null;
            }else{
            ac == myDataAC;
            }
            This IF-statement checks if your chart's current dataProvider {ac} is myDataAC. If it is, we'll reset the dataProvider {ac} to null. Else if your dataProvider {ac} is null, then it sets {ac} back to myDataAC

            Run your app, click the button, and watch your chart data reset to null. Click the button again and watch your chart re-populate.

            Hope this helps.
            • 3. Re: How do you clear the data on a chart?
              nikos101 Level 2
              Thanks very much for your helpful code, however I need this to be done without buttonclicks, is this possible?
              • 4. Re: How do you clear the data on a chart?
                EvolvedDSM Level 2
                An event needs to be called. How do you plan on calling an event to clear your data? I'll stay online with you while we work on this.
                • 5. Re: How do you clear the data on a chart?
                  nikos101 Level 2
                  I call the event now by a event. The following code applies:

                  Doing as you said I think this is what you mean:

                  for each (var ls:LineSeries in ratingsChart.series) {
                  for each (var ac:ArrayCollection in sortedChartData as ArrayCollection) {
                  var new1:ArrayCollection = ac;
                  var new2:ArrayCollection = new1;
                  ls.dataProvider = new2;
                  new2 = null;
                  }
                  }
                  • 6. Re: How do you clear the data on a chart?
                    nikos101 Level 2
                    Pardon me, the correct code that works is:

                    for each (var ls:LineSeries in ratingsChart.series) {


                    var new1:ArrayCollection = ls.dataProvider as ArrayCollection;
                    var new2:ArrayCollection = new1;
                    ls.dataProvider = new2;
                    new2.removeAll();

                    }

                    thanks very much Evolved