Adding one line to another, is this possible?

Jun 16, 2013 at 6:05 PM
__First and the most important:__GREAT library. Thank you.

Does OxyPlot support addition/subtraction/division/multiplication of line graphs? Say I have two series that have different X spacing, I can't add directly one to another because the X values do not exist. Please check this picture (done in Excel)

Image

Note that the line between each pair of points only exists while plotting. Is there a way of access that data for directly add all lines in the plot?

I've written a method for creating new points when they are needed but it's difficult to implement and not very good for performance. It would be great if someone guide me a little bit in the right direction. Thank you!
Coordinator
Jun 18, 2013 at 10:35 AM
Stacking is supported for BarSeries (that use category axes) but not for LineSeries and AreaSeries.
The easiest solution now would be to do the interpolation/extrapolation inside your application, this would also be better for performance (the LineSeries will need to interpolate every time it updates the data)

See also the fork stackedarealineseries:
https://oxyplot.codeplex.com/SourceControl/network/forks/benjaminrupp/StackedAreaLineSeries
Jun 18, 2013 at 12:04 PM
Edited Jun 18, 2013 at 12:16 PM
Thanks for the answer objo!

Here is the code for implementing Line addition in OxyPlot:
It checks if the line is null, and only plots where both lines exist.
I hope this may be useful for someone. I've received so much from the Internet and it's time to give something in return =)
Sorry but the variables/classes names are in Spanish (I don't have time right now to change them to English)

You need to call SumarNoEquiespaciado method that accepts two Lists of DataPoint.
class Operaciones
    {
        #region SumarNoEquiespaciado
        public static  IList<DataPoint> SumarNoEquiespaciado(IList<DataPoint> S1, IList<DataPoint> S2)
        {
            IList<DataPoint> Suma = new List<DataPoint>();
            IList<DataPoint> NS1 = new List<DataPoint>();
            IList<DataPoint> NS2 = new List<DataPoint>();

            

            if (S1.Any() && S2.Any())
            {
                
                NS1 = ObtenerPuntosIntermedios(S1, S2);
                NS2 = ObtenerPuntosIntermedios(S2, NS1);
                
                Suma = SumarEquiespaciado(NS1, NS2);
                
            }

            return Suma;
        }
        #endregion

        #region SumarEquiespaciado

        public static  IList<DataPoint> SumarEquiespaciado(IList<DataPoint> S1, IList<DataPoint> S2)
        {

            List<DataPoint> Suma = new List<DataPoint>();
            int PuntosEnS1 = S1.Count;
            int PuntosEnS2 = S2.Count;

            if (S1.Any() && S2.Any())
            {

                if (S1[0].X >= S2[0].X)
                {

                    if (S1[PuntosEnS1 - 1].X >= S2[PuntosEnS2 - 1].X)
                    {

                        Suma = SumarEquiespaciadoCaso2(S1, S2).ToList();
                    }

                    if (S1[PuntosEnS1 - 1].X < S2[PuntosEnS2 - 1].X)
                    {

                        Suma = SumarEquiespaciadoCaso1(S1, S2).ToList();
                    }
                }
                else
                {
                    if (S2[PuntosEnS2 - 1].X >= S1[PuntosEnS1 - 1].X)
                    {
                        Suma = SumarEquiespaciadoCaso2(S2, S1).ToList();
                    }

                    if (S2[PuntosEnS2 - 1].X < S1[PuntosEnS1 - 1].X)
                    {
                        Suma = SumarEquiespaciadoCaso1(S2, S1).ToList();
                    }

                }
            }


            return Suma;


        }

        #region Metodos De Ayuda para SumarEquiespaciado

        private static IList<DataPoint> SumarEquiespaciadoCaso2(IList<DataPoint> S1, IList<DataPoint> S2)
        {
            IList<DataPoint> Suma = new List<DataPoint>();
            int PuntosEnS1 = S1.Count;
            int PuntosEnS2 = S2.Count;

            int i = 0;
            int j = S2.TakeWhile(p => p.X < S1[0].X).Count();

            while (j < PuntosEnS2)
            {

                DataPoint punto = new DataPoint(S1[i].X, S1[i].Y + S2[j].Y);
                Suma.Add(punto);
                i++;
                j++;

            }

            return Suma;
        }

        private static IList<DataPoint> SumarEquiespaciadoCaso1(IList<DataPoint> S1, IList<DataPoint> S2)
        {
            IList<DataPoint> Suma = new List<DataPoint>();
            int PuntosEnS1 = S1.Count;
            int PuntosEnS2 = S2.Count;

            int i = 0;
            int j = S2.TakeWhile(p => p.X < S1[0].X).Count();

            while (i < PuntosEnS1)
            {

                DataPoint punto = new DataPoint(S1[i].X, S1[i].Y + S2[j].Y);
                Suma.Add(punto);
                i++;
                j++;

            }

            return Suma;
        }


        #endregion




        #endregion

        #region ObtenerPuntosIntermedios


        private static IList<DataPoint> ObtenerPuntosIntermedios(IList<DataPoint> S1, IList<DataPoint> S2)
        {
            IList<DataPoint> NS1 = new List<DataPoint>();

            int i = 0;
            int j = S2.TakeWhile(p => p.X < S1[0].X).Count();


            int PuntosEnS1 = S1.Count;
            int PuntosEnS2 = S2.Count;

            DataPoint nuevoPunto = new DataPoint();


            while (i < PuntosEnS1)
            {
                if (j < PuntosEnS2)
                {
                    if (S1[i].X < S2[j].X)
                    {
                        nuevoPunto = S1[i];
                        NS1.Add(nuevoPunto);
                        i++;
                    }

                    else if (S1[i].X == S2[j].X)
                    {

                        nuevoPunto = S1[i];
                        NS1.Add(nuevoPunto);
                        i++;
                        j++;
                    }

                    else if (S1[i].X > S2[j].X)
                    {
                        nuevoPunto.X = S2[j].X;
                        nuevoPunto.Y = S1[i - 1].Y + (S2[j].X - S1[i - 1].X) * (S1[i].Y - S1[i - 1].Y) / (S1[i].X - S1[i - 1].X);
                        NS1.Add(nuevoPunto);
                        j++;

                    }

                }

                if ((j == PuntosEnS2) && (S1[PuntosEnS1 - 1].X != S2[PuntosEnS2 - 1].X))
                {
                    nuevoPunto = S1[i];
                    NS1.Add(nuevoPunto);
                    i++;
                }


            }

           
            return NS1;

        }

        #endregion
    }