Page 1 of 1

Relating series position to bottom axes position

Posted: Mon Nov 30, 2009 9:43 am
by 13052926
Hi

I need to know if there is a way to relate a point in a series values collection (for example position 1 in the series.yvalues) to it's relative position along the bottom axes? Series (in my usage anyway) do not always start plotting from the first point on the chart. For example the first bottom axes point may be 1 Jan 2009 but one of the series only starts plotting from 1 Feb 2009. So I need to know that yvalue item 1 in the series is plotted at the 21st tick along the bottom axes.

Re: Relating series position to bottom axes position

Posted: Mon Nov 30, 2009 12:55 pm
by 10050769
Hello rossmc,
I need to know if there is a way to relate a point in a series values collection (for example position 1 in the series.yvalues) to it's relative position along the bottom axes?
I recommend use line2.CalcXPos (index), line2.CalcYPos (index) or similar methods that calculate for determined index his position in the screen. If it doesn't solve your problem or is not what you want, please explain exactly what would you do, because we can try to find a solution.

Thanks,

Re: Relating series position to bottom axes position

Posted: Mon Nov 30, 2009 2:11 pm
by 13052926
Those methods appear to return screen co-ordinates which won't help unless I can then convert the screen co-ordinate into a bottom axes value?

Re: Relating series position to bottom axes position

Posted: Mon Nov 30, 2009 3:11 pm
by yeray
Hi rossmc,

I'm not sure to understand what are you exactly trying to do either. If you want to get the first Y value of a series you can do series.YValue[0], if you want to get the Y coordinate in pixels that corresponds to that Y value, you can do as Sandra told you Series.CalcYPos(0). And the same applies for the X values, if you know the index of the value you want to get, series.XValue[index].

Also note that you can use the axes CalcPosValue and CalcPosPoint methods to calculate the pixel position for a given value or vice versa.

If you still find problems with it, please, try to explain what is your exact situation and/or send us a simple example project we can run as-is to reproduce the problem here.

Re: Relating series position to bottom axes position

Posted: Tue Dec 01, 2009 6:23 am
by 13052926
I'll have another go at trying to explain this:

Let's assume I have 260 price points to plot. The bottom axes then represents one year from 1 Jan to 31 Dec. (Saturdays and Sundays excluded).

I then want to overlay a second price stream on the same chart using the same axes.

This second price stream only has prices from the beginning of Feb. This means the second price stream will not start at the beginning of the bottom axes, but only after a gap that is twenty points along the bottom axes.

Now I calculate a third, new line based on the second lines valuelist. This third line needs to start plotting at the same starting position in time, along the bottom axes, as the second line.

Now, without writing a bunch of code around this, I wanted to know if there is a method in the chart control that can tell me that the second line only starts plotting at the twentieth point along the bottom axes? (In other words, series.yvalue(0) is above bottom axes point 20)?

Re: Relating series position to bottom axes position

Posted: Wed Dec 02, 2009 12:27 pm
by yeray
Hi rossmc,

If I understood you well this example is doing what you want. Note that you can create your second series' first X Value taking your first series' 20th value or creating the DateTime directly if you know the exact day.

Code: Select all

        private void InitializeChart()
        {
            chartController1.Chart = tChart1;

            tChart1.Aspect.View3D = false;

            Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);

            points1.XValues.DateTime = true;

            DateTime tmpdate = new DateTime(2009,01,01);
            Random rnd = new Random();
            points1.Add(tmpdate, rnd.Next(100));
            tmpdate = tmpdate.AddDays(1);            
            while (tmpdate < new DateTime(2010,01,01))
            {
                if ((tmpdate.DayOfWeek != DayOfWeek.Saturday) && (tmpdate.DayOfWeek != DayOfWeek.Sunday))
                    points1.Add(tmpdate,points1.YValues[points1.Count-1] + rnd.Next(10) - 5);
                tmpdate = tmpdate.AddDays(1);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Steema.TeeChart.Styles.Points points2 = new Steema.TeeChart.Styles.Points(tChart1.Chart);

            points2.XValues.DateTime = true;

            //DateTime tmpdate = new DateTime(2009, 02, 01);
            DateTime tmpdate = tChart1[0].XValues.AsDateTime(20);
            Random rnd = new Random();
            points2.Add(tmpdate, rnd.Next(100));
            tmpdate = tmpdate.AddDays(1);
            while (tmpdate < new DateTime(2010, 01, 01))
            {
                if ((tmpdate.DayOfWeek != DayOfWeek.Saturday) && (tmpdate.DayOfWeek != DayOfWeek.Sunday))
                    points2.Add(tmpdate, points2.YValues[points2.Count - 1] + rnd.Next(10) - 5);
                tmpdate = tmpdate.AddDays(1);
            }
        }