Stackable LineSeries. Is it possible?

Jul 14, 2013 at 5:15 PM
Hi,
I was wondering if it is possible to stack line series, to get something like this:


Image


I've been looking in the examples, but didn't find any similar...
Thank you
Jul 14, 2013 at 6:31 PM
If the LineSeries have the same X spacing you could create a new one and run a "foreach (DataPoint point in ...)" loop, adding the previous LineSeries to the current. If that is not enough and you want to have the same look as in your picture you should create AreaSeries, where the top line is the addition of the desired lines, and the low line is the lowest line.

If you have different X spacing you can't stack the lines point-per-point, you need first generate intermediate points in both lines, and then proceed with the addition.

Good luck
Jul 14, 2013 at 7:11 PM
Thanks, your AreaSeries solution was exactly what I was looking for.

Image
public IEnumerable<AreaSeries> StackLineSeries(IList<LineSeries> series)
        {
            double[] total = new double[series[0].Points.Count];

            LineSeries lineSeries;
            AreaSeries areaSeries;

            for (int s = 0; s < series.Count; s++)
            {
                lineSeries = series[s];
                areaSeries = new AreaSeries();

                for (int p = 0; p<lineSeries.Points.Count; p++)
                {
                    double x = lineSeries.Points[p].X;
                    double y = lineSeries.Points[p].Y;

                    areaSeries.Points.Add(new DataPoint(x, total[p]));
                    total[p] += y;
                    areaSeries.Points2.Add(new DataPoint(x, total[p]));
                }

                yield return areaSeries;
            }
        }