Page 1 of 1
Snapping a Drawline handle to a Value.
Posted: Tue Jul 20, 2010 7:04 am
by 8751509
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.
Re: Snapping a Drawline handle to a Value.
Posted: Wed Jul 21, 2010 12:26 pm
by narcis
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]);
}
Re: Snapping a Drawline handle to a Value.
Posted: Thu Jul 22, 2010 3:56 am
by 8751509
Cheers ....