9 Replies Latest reply on Jun 21, 2009 8:45 AM by leybniz

    Add new Values to CategoryAxis when a new serie is added

    lerooooogk

      Hi all,

       

      i'm working with and I found myself with a problem when i'm trying to add new series.

       

          <mx:ColumnChart id="cChart" height="100%" width="100%" dataProvider="{dataChart}" showDataTips="true"
                          >
              <mx:horizontalAxis>
                  <mx:CategoryAxis id="cAxis" categoryField="{nameField}"/>
              </mx:horizontalAxis>
              <mx:series>
                  <mx:ColumnSeries yField="{field}" xField="{nameField}" displayName="{displayName}" />
              </mx:series>
          </mx:ColumnChart>

       

      DataProvider is an array something like that:

      - Datachart ----> [nameField:A, field:20;

                               nameField:B, field:30;

                               nameField:C, field:80]

       

      In my app, user cans add new serie after creating the chart. For example, imagine that he wants to put on the chart the next Values:

      - Datachart ----> [nameField:A, field:13;

                               nameField:B, field:62;

                               nameField:D, field:30

                               nameField:E, field:92]

       

      Now, begin the problem:

      when the chart is refresh (adding series with AS) the values on categoryAxis are the same the old ones. In these case ('A',B','C') but the new ones dont appear ('D','E').

       

      Is there anyway to solve that problem?

        • 1. Re: Add new Values to CategoryAxis when a new serie is added
          _Natasha_ Level 4

          Hi,

          try to reset dataProvider for chart after adding new series.

          Something like this

          cChart.dataProvider = cChart.dataProvider

          1 person found this helpful
          • 2. Re: Add new Values to CategoryAxis when a new serie is added
            leybniz Level 4

            or try this one:

            ICollectionView(cChart.dataProvider).refresh();

            after you've made some changes to the collection.

             

            Actually there are two solutions:

            1. Use ArrayCollection instead of Array

            2. Once you are using Array, Chart will create internal ArrayCollection implicitly, so you have to update it manually using code above.

            1 person found this helpful
            • 3. Re: Add new Values to CategoryAxis when a new serie is added
              lerooooogk Level 1

              Hi,

               

              thanks both for your answers.

               

              I'm still having the same problem. Probably, I'm doing something (or all ) wrong.

               

              My code to addSeries is the next (i take data from a TitleWindow):

               

                          private function addSeries(event:Event):void{
                              PopUpManager.removePopUp(window);
                              var series1:ColumnSeries = new ColumnSeries();
                              series1.dataProvider = window.dataChart;
                              var option:String = window.option;
                              if (option == '1')
                              {
                                  series1.xField = 'paramValueToTag';
                                  //nameField2 = 'paramValueToTag';
                                  series1.yField = 'paramValueToDraw';
                                  series1.displayName = window.paramNameToDraw;
                                 
                              }
                              if (option == '2')
                              {
                                -----------
                              }

                             //Add series to Chart
                              var currentChart:Array = cChart.series;
                              currentChart.push(series1);
                              cChart.series = currentChart;


                            for (var i:int=0; i < window.dataChart.length(); i++){

                              dataChart.push(window.DataChart[i]);               
                          }

               

                          //Refresh dataProvider

                         cChart.dataProvider = dataChart;

              }

               

              The new values in categoryAxis dont appear.

              • 4. Re: Add new Values to CategoryAxis when a new serie is added
                leybniz Level 4

                Are you sure that marked parts represents the same variable?

                 

                for (var i:int=0; i < window.dataChart.length(); i++){

                                dataChart.push(window.DataChart[i]);              

                • 5. Re: Add new Values to CategoryAxis when a new serie is added
                  lerooooogk Level 1

                  w

                  Hi,

                   

                  yes.In my app is writed correctly. In the code I posted before I wrote wrong. Sorry

                   

                  for (var i:int=0; i < window.dataChart.length(); i++){

                                  dataChart.push(window.dataChart[i]); 

                   

                   

                  I show you the dataProvider exactly:

                   

                  dataChart

                  ------------------

                  • [0]
                    • paramValueToTag = "A"
                    • paramValueToDraw = "33"
                  • [1]
                    • paramValueToTag = "B"
                    • paramValueToDraw = "85"
                  • [2]
                    • paramValueToTag = "C"
                    • paramValueToDraw = "11"

                   

                  windowDataChart

                  ------------------------------

                  • [0]
                    • paramValueToTag = "A"
                    • paramValueToDraw = "30"
                  • [1]
                    • paramValueToTag = "F"
                    • paramValueToDraw = "95"
                  • [2]
                    • paramValueToTag = "B"
                    • paramValueToDraw = "10"
                  • [3]
                    • paramValueToTag = "C"
                    • paramValueToDraw = "80"
                  • [4]
                    • paramValueToTag = "D"
                    • paramValueToDraw = "11"
                  • [5]
                    • paramValueToTag = "E"
                    • paramValueToDraw = "12"

                   

                  With these values in the chart only appears:

                   

                  CategoryAxis ---> A,B,C with the values (paramValueToDraw) of both arrays.

                   

                  I hope you can understand better my problem

                   

                  Thanks in advance

                  • 6. Re: Add new Values to CategoryAxis when a new serie is added
                    leybniz Level 4

                    Replace this part:

                     

                    var currentChart:Array = cChart.series;
                    currentChart.push(series1);
                    cChart.series = currentChart;  // This code doing nothing!

                     

                    with

                     

                    var currentChart:Array = cChart.series.reverse().reverse();
                    currentChart.push(series1);
                    cChart.series = currentChart; // But this one does!

                     

                    this is to make sure you will create NEW array instead of using the reference to the old one.

                    • 7. Re: Add new Values to CategoryAxis when a new serie is added
                      lerooooogk Level 1

                      This is a nightmare for me!!

                       

                      Now, the values appear in the Chart but in a wrong display. Its a thing a bit "rare".

                       

                      Now , in category axis in chart appear these values:

                       

                      A,B,C,A,F,B,C,D,E

                       

                      Bold value has no values (i dont know the reason they appear...)

                      Underline --> that three are perfect, correct values in vertical axis and for both series

                      Italic ---> incorrect values, for both series the value in vertical axis is the same.

                       

                      Thanks for your help, really i dont know if I'm working in the correct direction with that.

                      • 8. Re: Add new Values to CategoryAxis when a new serie is added
                        leybniz Level 4

                        I guess you are the only one who knows the routes

                        little more understanding and debugging will lead you to success, I'm sure!

                         

                        Please always mark helpful messages, so others reading this thread catch up most valuable texts quicker Thanks!

                        • 9. Re: Add new Values to CategoryAxis when a new serie is added
                          lerooooogk Level 1

                          I'm the worst.

                           

                          I wanted to mark helpful messages but I marked correct answer (well, really all answer are correct...)

                           

                          I'll try again tomorow (I've been "working" on that by 12 hours today).

                           

                          I hope that I could write the solution here!!

                           

                          Thanks for all!