Snapping a Drawline handle to a Value.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Snapping a Drawline handle to a Value.

Post by Snarkle » Tue Jul 20, 2010 7:04 am

Greetings,

Is there a way to 'snap' a drawline's handle to the nearest point of the desired type ... for example snapping a drawLine handle to the close price of an OHLC point.
Or is there a way to at least 'know' what the closest point is and then adjust the DrawlineItems.startPos/endPos method.

I'm thinking this must be possible as the nearestPoint tool certainly can figure it out.

Cheers Phil.
--------------------
Cheers Phil.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Snapping a Drawline handle to a Value.

Post by Narcís » Wed Jul 21, 2010 12:26 pm

Hi Phil,

Yes, you can use NearestPoint tool for that, for example:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            CreateTeeChartComponents();
            InitializeChart();
        }
		
        private void InitializeChart()
        {
            tChart1.Series.Add(new Steema.TeeChart.Styles.Candle()).FillSampleValues();

            Steema.TeeChart.Tools.DrawLine drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
            drawLine1.Series = tChart1[0];
            drawLine1.DraggedLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawLine1_DraggedLine);
        }

        void drawLine1_DraggedLine(Steema.TeeChart.Tools.DrawLine sender)
        {
            CalcNearestLine(sender);
        }

        private void CalcNearestLine(Steema.TeeChart.Tools.DrawLine drawLineTool)
        {
            Steema.TeeChart.Styles.Series s = (drawLineTool.Series == null) ? tChart1[0] : drawLineTool.Series ;
            Steema.TeeChart.Tools.NearestPoint nearestPoint1 = new Steema.TeeChart.Tools.NearestPoint(s);
            Steema.TeeChart.Tools.DrawLineItem line = new Steema.TeeChart.Tools.DrawLineItem();
            line = drawLineTool.Selected;

            Point P0 = new Point(s.CalcXPosValue(line.StartPos.X), s.CalcYPosValue(line.StartPos.Y));
            Point P1 = new Point(s.CalcXPosValue(line.EndPos.X), s.CalcYPosValue(line.EndPos.Y));
            
            int index0 = nearestPoint1.GetNearestPoint(P0);
            int index1 = nearestPoint1.GetNearestPoint(P1);
            nearestPoint1.Series = null;

            line.StartPos = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index0], s.YValues[index0]);
            line.EndPos = new Steema.TeeChart.Drawing.PointDouble(s.XValues[index1], s.YValues[index1]);
        }
Best Regards,
Narcís Calvet / 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

Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Re: Snapping a Drawline handle to a Value.

Post by Snarkle » Thu Jul 22, 2010 3:56 am

Cheers ....
--------------------
Cheers Phil.

Post Reply