Group: Forum Members
Last Active: 8 Years Ago
Posts: 61,
Visits: 35
|
Hi,
I asked this question before and I got some code which is working alright but it turns really slow if there are more thousands of data points. I'm trying to get the current data points for the displayed lines at a user chosen coordinate on the graph.
I got "this"(I made some changes) code from you before: //j is a counter in a loop of line series NLineSeries graphLine = (NLineSeries)chart.Series[j]; if (graphLine.Visible) { NViewToScale2DTransformation view2Scale = new NViewToScale2DTransformation(nChartControl1.View.Context, chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);
NVector2DD vecScale = new NVector2DD(); view2Scale.Transform(new NPointF(graphLinePanel.Left, 0), ref vecScale);
int count = graphLine.Values.Count;
if (count > 0) { minIndex = 0; double minDistance = GetDistanceFromDataPoint(graphLine, 0, vecScale); graphLine.FillStyles.Clear();
int i = 1; double curDistance = GetDistanceFromDataPoint(graphLine, i, vecScale); while (i < count && minDistance >= curDistance) { curDistance = GetDistanceFromDataPoint(graphLine, i, vecScale); if (curDistance < minDistance) { minDistance = curDistance; minIndex = i; } i++; } } }
double GetDistanceFromDataPoint(NLineSeries graphLine, int index, NVector2DD vec) { double x; double y = (double)graphLine.Values[index];
if (graphLine.UseXValues) { x = (double)graphLine.XValues[index]; } else { x = index; }
double dx = vec.X - x; double dy = vec.Y - y;
return dx * dx; }
Just wondering if you have any faster function implemented by now? Or do you think that could be rewritten to be more efficient?
Thank you, Daniel
|