4 Replies Latest reply on Jul 13, 2010 1:28 PM by rtalton

    Losing series from chart when adding one

    Bryan.Sampieri

      I have a problem with adding a LineSeries to an existing chart.  It's a LineChart (but also tried bases of CartesianChart, CandlestickChart, ColumnChart, HLOCChart and AreaChart), which has a ColumnSeries (volume) and CandlestickSeries (stock prices).  When I add the LineSeries on the chart, the column series always disappears (and the right axis it's tied to loses the min/max range it had).  It doesn't seem to matter which order the series are in the list, always the ColumnSeries disappears.  Tried all the invalidateXxx methods on the chart, doesn't seem to matter.

       

              var sma1Series:LineSeries = new LineSeries();
              sma1Series.horizontalAxis = laCarta.timeAxis;
              sma1Series.verticalAxis = laCarta.leftAxis;
              sma1Series.xField = "time";
              sma1Series.yField = "sma";
              sma1Series.dataProvider = sma.data;
              sma1Series.displayName = symbol + " SMA (" + sma.period + ")";
              sma1Series.setStyle("lineStroke", styles.sma1Stroke);

       

              var series:Array = laCarta.series // volume and symbol series
              series.push(sma1Series);
              laCarta.series = series;

       

      I can print out the series list after adding, they are all there.  Is there something I'm missing here? I can't find any reference to this issue anywhere.


      Building with Flex 3.5, running in Flash player 10.

        • 1. Re: Losing series from chart when adding one
          Bryan.Sampieri Level 1

          sorry for the duplicate... didn't realize the first one posted...

          • 2. Re: Losing series from chart when adding one
            Bryan.Sampieri Level 1

            This is odd.  If I start with just the CandlestickSeries alone, then programatically add the volume (ColumnSeries) series, it adds fine.  If I then add the overlay LineSeries to the same set, it still kills the ColumnSeries, when doing it as a separate operation (e.g. button 1 adds ColumnSeries, button 2 adds LineSeries).

             

            But if I add both ColumnSeries and LineSeries at the same time, even separately, it works.  For example, below works just fine, whether together == true or false.

             

            public function addSeries(together:Boolean):void {

                    var vr:AxisRenderer = createAxisRenderer(createAxis("Volume", 0);); // separate axis/renderer for volume
                    var vc:ColumnSeries = createVolumeSeries(main.timeAxis, vr.axis);

             

                    var sma1Series:LineSeries = createSMASeries(main.timeAxis, main.leftAxis);

             

                    if(together) { // push them together

                      main.series.unshift(vc); // put it first/bottom
                       main.series.push(sma1Series);
                       main.series = main.series;
                       main.verticalAxisRenderers.push(vr); // add renderer
                       main.verticalAxisRenderers = main.verticalAxisRenderers;

                    } else { // add one, then the other

                      main.series.unshift(vc); // put it first/bottom
                       main.series = main.series;
                       main.verticalAxisRenderers.push(vr); // add renderer
                       main.verticalAxisRenderers = main.verticalAxisRenderers;

                      main.series.push(sma1Series);
                       main.series = main.series;

                    }

            }

            • 3. Re: Losing series from chart when adding one
              Bryan.Sampieri Level 1

              Another clue, in case anyone is following.  I don't understand what, but something odd seems to be happening internally in the CartesianChart class when series are set... The main chart MXML has the 2 primary series (column and candlestick)  pre-defined, with the left and right axis defined in candelstick and column series, respectively.

               

              It seems there is something funny going on with the  handling of the right-side axis when changing series, like something is  cleared out and not reset.  I had also tried to explicitly reset the column  series axis before/after setting the series, for example:

               

                       var ra:IAxis = main.rightAxis;
                       main.series = series; // includes new series

                      (main.volumeSeries as ColumnSeries).verticalAxis = ra; // force reset axis on original series

               

              But that didn't work either. However...

               

              If I explicitly declare the right-side axis (used by the column series) as the main chart's vertical axis (as opposed to declaring it in the column series), then I can add/remove the new LineSeries (which was always tied to the left-side axis anyway) without losing the original ColumnSeries.  The left-side axis is still declared within the CandlestickSeries.

               

              It appears I have to do this, or to explcitly recreate whole new series, axes and axis renderers for each series every time I just want to add/remove some overlay.

              • 4. Re: Losing series from chart when adding one
                rtalton Level 4

                I've also had trouble using actionscript to modify charts declared in MXML at run time. It just seems to be the nature of the beast. Wish I could be more helpful, but just wanted you to know you are not alone.