Draw line tool behaving strange
Posted: Wed Aug 12, 2009 1:09 pm
Hi TeaChart Team,
I am using the nearest point tool to get the nearest point out of 100 fast line serieses. I am able to get the nearest point value correctly. Now i want to draw a vertical dashed line from that nearest point to my bottom axis with a circle at the point. For drawing the line i am using the DrawLine tool. I have 3000 data points in each series. Using the draw line tool i am able to draw the line also but after a certain value of x-axis (if the valueIndex > 2000 or so) - the line is not getting drawn. Please see the code below -
Once the 'ValueIndex' goes beyond 2000 or 2100, line is not getting drawn.
Please let me know if i am doing something wrong.
I am using the nearest point tool to get the nearest point out of 100 fast line serieses. I am able to get the nearest point value correctly. Now i want to draw a vertical dashed line from that nearest point to my bottom axis with a circle at the point. For drawing the line i am using the DrawLine tool. I have 3000 data points in each series. Using the draw line tool i am able to draw the line also but after a certain value of x-axis (if the valueIndex > 2000 or so) - the line is not getting drawn. Please see the code below -
Code: Select all
private void TeeChart_MouseMove(object sender, MouseEventArgs e)
{
if (TeeChart.Series.Count <= 0) return;
CalCulateNearestPoint(e);
}
private void CalCulateNearestPoint(MouseEventArgs e)
{
int[] NearestPoints;
int SeriesIndex, ValueIndex;
double Dist, tmp;
Point P1, P2;
NearestPoints = new int[TeeChart.Series.Count];
P1 = new Point(0, 0);
P2 = new Point(TeeChart.Width, TeeChart.Height);
SeriesIndex = 0;
ValueIndex = 0;
for (int i = 0; i < NearestPoints.Length; i++)
{
_NearestPointTool.Series = TeeChart.Series[i];
NearestPoints[i] = _NearestPointTool.GetNearestPoint(new Point(e.X, e.Y));
}
_NearestPointTool.Series = null;
Dist = Distance(P1, P2);
int StartPt = -1;
int EndPt = -1;
for (int i = 0; i < NearestPoints.Length; i++)
{
P1.X = TeeChart.Series[i].CalcXPos(NearestPoints[i]);
P1.Y = TeeChart.Series[i].CalcYPos(NearestPoints[i]);
P2.X = e.X;
P2.Y = e.Y;
tmp = Distance(P1, P2);
if ((i == 0) || (tmp < Dist))
{
Dist = tmp;
SeriesIndex = i;
ValueIndex = NearestPoints[i];
}
}
if (_DrawLine != null)
TeeChart.Tools.Remove(_DrawLine);
TeeChart.Tools.Add(_DrawLine = new DrawLine());
_DrawLine.EnableDraw = false;
_DrawLine.Button = MouseButtons.XButton2;
_DrawLine.Series = TeeChart.Series[SeriesIndex];
_DrawLine.Pen.Color = Color.Gray;
_DrawLine.Pen.Width = 1;
_DrawLine.Pen.DashPattern = new float[] { 4.0f, 4.0f, 2.0f, 2.0f, 4.0f };
_DrawLine.Pen.Style = System.Drawing.Drawing2D.DashStyle.Custom;
_DrawLine.Pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
_DrawLine.Pen.DashCap = System.Drawing.Drawing2D.DashCap.Round;
DrawLineItem _DrawLineItem = new DrawLineItem(_DrawLine);
_DrawLineItem.StartPos = new Steema.TeeChart.Drawing.PointDouble((double)ValueIndex, 0);
_DrawLineItem.EndPos = new Steema.TeeChart.Drawing.PointDouble((double)ValueIndex, TeeChart.Series[SeriesIndex].YValues[ValueIndex]);
_DrawLine.Invalidate();
if (_AnnotationTool != null)
TeeChart.Tools.Remove(_AnnotationTool);
_AnnotationTool = new Annotation(TeeChart.Chart);
TeeChart.Tools.Add(_AnnotationTool);
_AnnotationTool.Text = "Series: " + TeeChart.Series[SeriesIndex].Title + " - ValueIndex: " + TeeChart.Series[SeriesIndex].YValues[ValueIndex].ToString() + " - Label: " + lTimeStamps[ValueIndex];
_AnnotationTool.Left = e.X + 5;
_AnnotationTool.Top = e.Y - 25;
}
private double Distance(Point Pt1, Point Pt2)
{
int dx, dy;
dx = Pt1.X - Pt2.X;
dy = Pt1.Y - Pt2.Y;
return Math.Sqrt((dx * dx) + (dy * dy));
}
Please let me know if i am doing something wrong.