Movement in Line Series

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Movement in Line Series

Post by Amol » Wed Apr 06, 2011 1:51 pm

Hello,

Thanks for the support you have provided so far.
I am creating a line series having two points. I can also move these points by clicking and dragging it by mouse so that whole line may change. My requirement is, to create a straight line in which the line passing through these points should always touch the boundaries of chart even when I move it. In addition I can say the series which I see on chart every time should always be a straight line.

For more help I am sending you two snaps of my requirement. First snap shows initial position of graph, and second one shows the series after moving it by mouse.
Initial Posiition of Points.jpg
initial position of graph
Initial Posiition of Points.jpg (67.59 KiB) Viewed 18543 times
Second Position of Point.jpg
series after moving it by mouse
Second Position of Point.jpg (95.25 KiB) Viewed 18525 times
Please help me as soon as possible.

Thanks in advance for your support

Thanking and regards
Ashish Pandey

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Movement in Line Series

Post by Sandra » Thu Apr 07, 2011 11:10 am

Hello Amol,

I'm not sure to understand how would you exactly want it to do. It would be helpful if you could arrange a simple example project we can run as-is to reproduce the situation here. And also please tell us which version are you using now?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Movement in Line Series

Post by Amol » Fri Apr 08, 2011 2:29 pm

Hi Sandra,
Thanks for your reply. As you ask me about version then this is Tee Chart version 4 (Trail version).
I am again trying to explain my problem-
1. Suppose one straight line drawn on tee chart (In such manner that the end points of line touch the boundaries of tee chart).
2. On that straight line. Two pointers are being displayed in mid of line (Points are not overlapping).
3. Now drag any one pointer then straight line should also drag along with this point joining with other pointer and line should always touch the boundaries of tee chart. (As mentioned in point 1).
Hope you understand what I am trying to convey you. In short, I have one straight line drawn on tee chart having two pick points. When we drag any pick point then that straight line should also move with that pick point and on tee chat that straight line should always present which is passing through those two pick points and touching the tee chart boundaries.

Another problem –
I have one straight line drawn on tee chart at any slope say 45 degree. Now drag that line and drop at another location. Line should drop with same slope, In this case 45 degree.

Please help me as soon as possible.

Thanks in advance for your support

Thanking and regards
Ashish Pandey

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Movement in Line Series

Post by Yeray » Tue Apr 12, 2011 9:03 am

Hello Ashish,

I think you could use the DrawLine Tool. You could hide the line pen and calculate the coordinates where the line would touch the Chart rectangle. Known the angle formed by the StartPos and EndPos points, this can be done with some trigonometry calculations. Here it is an example:

Code: Select all

        Steema.TeeChart.Styles.Points points1;
        Steema.TeeChart.Tools.DrawLine drawline1;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Legend.Visible = false;

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

            drawline1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
            drawline1.NewLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawline1_NewLine);

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            for (int i = 0; i < drawline1.Lines.Count; i++)
            {
                int X0 = tChart1.Axes.Bottom.CalcPosValue(drawline1.Lines[i].StartPos.X);
                int Y0 = tChart1.Axes.Left.CalcPosValue(drawline1.Lines[i].StartPos.Y);
                int X1 = tChart1.Axes.Bottom.CalcPosValue(drawline1.Lines[i].EndPos.X);
                int Y1 = tChart1.Axes.Left.CalcPosValue(drawline1.Lines[i].EndPos.Y);
                int X3, Y3, X4, Y4;

                double alfa = Math.Atan2(Y1 - Y0, X1 - X0);
                double alfad = (alfa * (180.0 / Math.PI)) % 360;

                if ((alfad == 90) || (alfad == -90))
                {
                    g.VerticalLine(X0, tChart1.Axes.Left.IStartPos, tChart1.Axes.Left.IEndPos);
                }
                else if ((alfad == 180) || (alfad == 0))
                {
                    g.HorizontalLine(tChart1.Axes.Bottom.IStartPos, tChart1.Axes.Bottom.IEndPos, Y0);
                }
                else if ((alfad > 90) || ((alfad > -90) && (alfad < 0)))
                {
                    X3 = Math.Max(X1 + (int)((tChart1.Axes.Left.IEndPos - Y1) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos);
                    Y3 = Math.Min(Y1 + (int)(Math.Tan(alfa) * (tChart1.Axes.Bottom.IStartPos - X1)), tChart1.Axes.Left.IEndPos);
                    X4 = Math.Min(X0 + (int)((tChart1.Axes.Left.IStartPos - Y0) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos);
                    Y4 = Math.Max(Y0 + (int)(Math.Tan(alfa) * (tChart1.Axes.Bottom.IEndPos - X0)), tChart1.Axes.Left.IStartPos);

                    g.Line(X3, Y3, X4, Y4);
                }
                else
                {
                    X3 = Math.Max(X0 + (int)((tChart1.Axes.Left.IStartPos - Y0) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos);
                    Y3 = Math.Max(Y1 - (int)(Math.Tan(alfa) * (X1 - tChart1.Axes.Bottom.IStartPos)), tChart1.Axes.Left.IStartPos);
                    X4 = Math.Min(X1 + (int)((tChart1.Axes.Left.IEndPos - Y1) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos);
                    Y4 = Math.Min(Y0 - (int)(Math.Tan(alfa) * (X0 - tChart1.Axes.Bottom.IEndPos)), tChart1.Axes.Left.IEndPos);

                    g.Line(X3, Y3, X4, Y4);
                }
            }
        }

        void drawline1_NewLine(Steema.TeeChart.Tools.DrawLine sender)
        {
            drawline1.Lines[drawline1.Lines.Count-1].Pen.Visible = false;
        }
The only problem I see with this solution is that only the segment between the two draggable points will be clickable, not the whole custom line.
However, I think this should still be possible with the mouse events.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Movement in Line Series

Post by Amol » Wed Apr 13, 2011 1:27 pm

Hi Yeray,

Thanks for your reply, we have tested this code and it works fine. That’s really great. Only I have couple of queries with this code snippet-
1. Want to change line colour too. (Means after rotating line at any point of time we can change line colour too)
2. Another query, as currently we have to create first line by dragging mouse and then we can rotate it by the help of picking pointer. In this only one improvement we want that instead of creating line by mouse, Line should be drawn by default at any location with two pick points. So that we can directly rotate line by choosing any pick point.

Is it possible by line series too? As I feel that using draw tool hurt the performance while rotating line.

I am very thankful for your kind and precious support.

Thanking and regards
Ashish Pandey

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Movement in Line Series

Post by Sandra » Fri Apr 15, 2011 7:59 am

Hello Amol,

Sorry for the delay.
1. Want to change line color too. (Means after rotating line at any point of time we can change line color too)
I think you can use to change the color of line g.Pen.Color in AfterDrawEvent as do in next lines of code:

Code: Select all

 g.Pen.Color = Color.Red;
2. Another query, as currently we have to create first line by dragging mouse and then we can rotate it by the help of picking pointer. In this only one improvement we want that instead of creating line by mouse, Line should be drawn by default at any location with two pick points. So that we can directly rotate line by choosing any pick point.
You can draw directly line using DrawLineItems and StartPos and EndPos properties as do in Yeray's code that I have modified of:

Code: Select all

        Steema.TeeChart.Styles.Points points1;
        Steema.TeeChart.Tools.DrawLine drawline1;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Legend.Visible = false;

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

            drawline1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
            drawline1.NewLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawline1_NewLine);
            Steema.TeeChart.Tools.DrawLineItem I = new Steema.TeeChart.Tools.DrawLineItem(drawline1);
            /* set the "Y" line positions (start and end position) */
            double tmp = points1.YValues.Range / 5.0;
            I.StartPos = new Steema.TeeChart.Drawing.PointDouble(5, (points1.YValues.Maximum - tmp));
            I.EndPos = new Steema.TeeChart.Drawing.PointDouble(15, (points1.YValues.Minimum + tmp));
            drawline1.EnableDraw = false;
           tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
         }
        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            for (int i = 0; i < drawline1.Lines.Count; i++)
            {
                int X0 = tChart1.Axes.Bottom.CalcPosValue(drawline1.Lines[0].StartPos.X);
                int Y0 = tChart1.Axes.Left.CalcPosValue(drawline1.Lines[0].StartPos.Y);
                int X1 = tChart1.Axes.Bottom.CalcPosValue(drawline1.Lines[0].EndPos.X);
                int Y1 = tChart1.Axes.Left.CalcPosValue(drawline1.Lines[0].EndPos.Y);
                int X3, Y3, X4, Y4;

                double alfa = Math.Atan2(Y1 - Y0, X1 - X0);
                double alfad = (alfa * (180.0 / Math.PI)) % 360;
                g.Pen.Color = Color.Red;

                if ((alfad == 90) || (alfad == -90))
                {
                     g.VerticalLine(X0, tChart1.Axes.Left.IStartPos, tChart1.Axes.Left.IEndPos);
                }
                else if ((alfad == 180) || (alfad == 0))
                {
                  g.HorizontalLine(tChart1.Axes.Bottom.IStartPos, tChart1.Axes.Bottom.IEndPos, Y0);
                }
                else if ((alfad > 90) || ((alfad > -90) && (alfad < 0)))
                {
                    X3 = Math.Max(X1 + (int)((tChart1.Axes.Left.IEndPos - Y1) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos);
                    Y3 = Math.Min(Y1 + (int)(Math.Tan(alfa) * (tChart1.Axes.Bottom.IStartPos - X1)), tChart1.Axes.Left.IEndPos);
                    X4 = Math.Min(X0 + (int)((tChart1.Axes.Left.IStartPos - Y0) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos);
                    Y4 = Math.Max(Y0 + (int)(Math.Tan(alfa) * (tChart1.Axes.Bottom.IEndPos - X0)), tChart1.Axes.Left.IStartPos);
                    g.Line(X3, Y3, X4, Y4);
                    
                }
                else
                {
                    X3 = Math.Max(X0 + (int)((tChart1.Axes.Left.IStartPos - Y0) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos);
                    Y3 = Math.Max(Y1 - (int)(Math.Tan(alfa) * (X1 - tChart1.Axes.Bottom.IStartPos)), tChart1.Axes.Left.IStartPos);
                    X4 = Math.Min(X1 + (int)((tChart1.Axes.Left.IEndPos - Y1) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos);
                    Y4 = Math.Min(Y0 - (int)(Math.Tan(alfa) * (X0 - tChart1.Axes.Bottom.IEndPos)), tChart1.Axes.Left.IEndPos);
                    g.Line(X3, Y3, X4, Y4);
                }
            }

        }
        void drawline1_NewLine(Steema.TeeChart.Tools.DrawLine sender)
        {
            drawline1.Lines[drawline1.Lines.Count - 1].Pen.Visible = false;
        }
Could you tell us if previous code works as you expected?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Movement in Line Series

Post by Amol » Sat Apr 16, 2011 9:44 am

Hi Sandra,

Thanks for your reply, we have tested previous code and it works fine. That’s really great. We are very much pleased with Steema’s support. Currently we have Licence of Tee-Chart V2 and we are evaluating V4 and will have its licence in upcoming 2 or 3 months.

We will try your code for our requirements, and surely tell about the response soon.

I am very thankful for your kind and precious support.

Thanking and regards
Ashish Pandey

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Movement in Line Series

Post by Amol » Tue May 24, 2011 6:44 am

Hi Sandra,

We are sorry as we could not give you feedback on your previous post due to some unavoidable reasons.
Your last post helped us to achieve what we were expecting. We can say it is almost near our requirement. But there are still some small issues in which your support might be helpful. Following are our queries:
• Can we add line drawn by ‘DrawLine’ tool in legend of chart?
• Can we prevent movement of whole line (as in our previous posts we have told you that we need movement of one pointer with respect to other one. To refresh remembrance you can see the requirements posted before.)
It will be very helpful if you please respond ASAP.

Thanks and Regards
Ashish Pandey

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Movement in Line Series

Post by Sandra » Wed May 25, 2011 8:23 am

Hello Amol,

Sorry for the delay.
• Can we add line drawn by ‘DrawLine’ tool in legend of chart?
I am afraid that it is not possible.
• Can we prevent movement of whole line (as in our previous posts we have told you that we need movement of one pointer with respect to other one. To refresh remembrance you can see the requirements posted before.)
Sorry I think don't understand good as you want do. Please, can you explain step to step you want achieve?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Movement in Line Series

Post by Amol » Wed May 25, 2011 1:57 pm

Hi Sandra,

Thanks for the response. Answer of first question is stopping us to use draw line tool. Hope we will achieve our requirement using line series after some R&D. If we need further assistance we will contact you for sure. Anyway it was good to have your precious support.

Thanks and Regards
Ashish Pandey

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Movement in Line Series

Post by Amol » Mon May 30, 2011 2:07 pm

Hi Sandra,

Thanks for the support you all provided us so far. I tried above using Line Series, but failed to achieve my requirement. You asked me to explain the requirement. So I am giving a link which can clarify what we need.

Please see the link:http://www.mathopenref.com/coordslope.html

In this example you can see that there are two points in the line and the end point of the line are touching the boundaries of chart. The line can be translated by holding one point with respect to another. More you can see in this example.
We want to implement this type graph in Tee-Chart. Please help us ASAP.

Thanks in advance.

Thanks and Regards
Ashish Pandey

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Movement in Line Series

Post by Yeray » Wed Jun 01, 2011 10:34 am

Hello Ashish,

You could create your own legend doing something similar to the example here.
I've adapted it to the example Sandra posted some posts above:

Code: Select all

        public class MyLegend : Steema.TeeChart.Drawing.TeeBase
        {
            public MyLegend() : this((Steema.TeeChart.Chart)null) { }
            public MyLegend(Steema.TeeChart.Chart c) : base(c) { }

            public void Draw(Steema.TeeChart.Drawing.Graphics3D g, Rectangle r)
            {
                int tmpY = r.Y;
                g.Rectangle(r);
                g.Font.Bold = true;
                for (int i = 0; i < base.Chart.Series.Count; i++)
                {
                    g.TextOut(r.X, tmpY, base.Chart[i].Title);
                    tmpY = tmpY + (int)g.TextHeight(base.Chart[i].Title);
                }
                for (int i = 0; i < base.Chart.Tools.Count; i++)
                {
                    if (base.Chart.Tools[i] is Steema.TeeChart.Tools.DrawLine)
                    {
                        Steema.TeeChart.Tools.DrawLine dl = base.Chart.Tools[i] as Steema.TeeChart.Tools.DrawLine;
                        for (int j = 0; j < dl.Lines.Count; j++)
			            {
                            string tmpstr = "DrawLineTool Line " + j.ToString();
			                g.TextOut(r.X, tmpY, tmpstr);
                            tmpY = tmpY + (int)g.TextHeight(tmpstr);
			            }
                    }
                }
            }
        }

        private Steema.TeeChart.TChart tChart1;
        private void CreateChart()
        {
            tChart1 = new Steema.TeeChart.TChart();
            this.Controls.Add(tChart1);

            Steema.TeeChart.ChartController tChartController1 = new Steema.TeeChart.ChartController();
            this.Controls.Add(tChartController1);
            tChartController1.Chart = tChart1;

            tChart1.Dock = DockStyle.Fill;
        }

        private Steema.TeeChart.Styles.Points points1;
        private Steema.TeeChart.Tools.DrawLine drawline1;
        private MyLegend myLegend;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Legend.Visible = false;
            tChart1.Panel.MarginRight = 40;

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

            myLegend = new MyLegend(tChart1.Chart);

            drawline1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
            drawline1.NewLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawline1_NewLine);
            drawline1.Pen.Color = Color.Red;

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }
        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            Steema.TeeChart.Drawing.ChartPen oldPen = new Steema.TeeChart.Drawing.ChartPen();
            oldPen.Assign(g.Pen);
            g.Pen.Assign(drawline1.Pen);

            for (int i = 0; i < drawline1.Lines.Count; i++)
            {
                int X0 = tChart1.Axes.Bottom.CalcPosValue(drawline1.Lines[i].StartPos.X);
                int Y0 = tChart1.Axes.Left.CalcPosValue(drawline1.Lines[i].StartPos.Y);
                int X1 = tChart1.Axes.Bottom.CalcPosValue(drawline1.Lines[i].EndPos.X);
                int Y1 = tChart1.Axes.Left.CalcPosValue(drawline1.Lines[i].EndPos.Y);
                int X3, Y3, X4, Y4;

                double alfa = Math.Atan2(Y1 - Y0, X1 - X0);
                double alfad = (alfa * (180.0 / Math.PI)) % 360;

                if ((alfad == 90) || (alfad == -90))
                {
                    g.VerticalLine(X0, tChart1.Axes.Left.IStartPos, tChart1.Axes.Left.IEndPos);
                }
                else if ((alfad == 180) || (alfad == 0))
                {
                    g.HorizontalLine(tChart1.Axes.Bottom.IStartPos, tChart1.Axes.Bottom.IEndPos, Y0);
                }
                else if ((alfad > 90) || ((alfad > -90) && (alfad < 0)))
                {
                    X3 = Math.Max(X1 + (int)((tChart1.Axes.Left.IEndPos - Y1) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos);
                    Y3 = Math.Min(Y1 + (int)(Math.Tan(alfa) * (tChart1.Axes.Bottom.IStartPos - X1)), tChart1.Axes.Left.IEndPos);
                    X4 = Math.Min(X0 + (int)((tChart1.Axes.Left.IStartPos - Y0) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos);
                    Y4 = Math.Max(Y0 + (int)(Math.Tan(alfa) * (tChart1.Axes.Bottom.IEndPos - X0)), tChart1.Axes.Left.IStartPos);
                    g.Line(X3, Y3, X4, Y4);

                }
                else
                {
                    X3 = Math.Max(X0 + (int)((tChart1.Axes.Left.IStartPos - Y0) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos);
                    Y3 = Math.Max(Y1 - (int)(Math.Tan(alfa) * (X1 - tChart1.Axes.Bottom.IStartPos)), tChart1.Axes.Left.IStartPos);
                    X4 = Math.Min(X1 + (int)((tChart1.Axes.Left.IEndPos - Y1) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos);
                    Y4 = Math.Min(Y0 - (int)(Math.Tan(alfa) * (X0 - tChart1.Axes.Bottom.IEndPos)), tChart1.Axes.Left.IEndPos);
                    g.Line(X3, Y3, X4, Y4);
                }
            }

            g.Pen.Assign(oldPen);
            myLegend.Draw(g, Steema.TeeChart.Utils.FromLTRB(tChart1.Width - 200, 100, tChart1.Width - 50, 250));
        }

        void drawline1_NewLine(Steema.TeeChart.Tools.DrawLine sender)
        {
            drawline1.Lines[drawline1.Lines.Count - 1].Pen.Visible = false;
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply