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.
Snapping a Drawline handle to a Value.
Snapping a Drawline handle to a Value.
--------------------
Cheers Phil.
Cheers Phil.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Snapping a Drawline handle to a Value.
Hi Phil,
Yes, you can use NearestPoint tool for that, for example:
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 |
Instructions - How to post in this forum |