I wonder if there is a function from TChartSeries that return a list a points Index from a TRect (Selection using mouse).
I did a lil search on the forum and i havent found anything about that.
Thanks.
Get Points Index from Rect
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Get Points Index from Rect
Hi GotoXY,
You could do the same as the examples discussed on this thread:
http://www.teechart.net/support/viewtopic.php?t=5385
You could do the same as the examples discussed on this thread:
http://www.teechart.net/support/viewtopic.php?t=5385
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 |
Re: Get Points Index from Rect
Looks like what im trying to do but in reverse. We have series with over 2m values so i think it would be more optimized my way.
What i do is convert my TRect values to values from the axis then vérified if (X >= X1) AND (X <= X2) etc..
From my point of view, converting the TRect will be less CPU usage since i do that only 1 time but i dont know if comparing Double will cost me more than comparing integer + the conversion
What i do is convert my TRect values to values from the axis then vérified if (X >= X1) AND (X <= X2) etc..
From my point of view, converting the TRect will be less CPU usage since i do that only 1 time but i dont know if comparing Double will cost me more than comparing integer + the conversion
Re: Get Points Index from Rect
Hi GoToXY,
I also think your method would be more optimized.
(A) Transform the Rect coordinates (pixels) to doubles (values) and, in the loop, compare doubles (Rect coordinates and Series Values).
(B) In the loop, transform Series Values to integers (pixels) and compare integers.
Note that in (B) "transform Series Values to integers (pixels)", the call to CalcXPos means some operations, concretely two sums of doubles, a product and a Round.
I don't think the difference between comparing integers and comparing doubles would compensate these extra operations.
I also think your method would be more optimized.
(A) Transform the Rect coordinates (pixels) to doubles (values) and, in the loop, compare doubles (Rect coordinates and Series Values).
(B) In the loop, transform Series Values to integers (pixels) and compare integers.
Note that in (B) "transform Series Values to integers (pixels)", the call to CalcXPos means some operations, concretely two sums of doubles, a product and a Round.
I don't think the difference between comparing integers and comparing doubles would compensate these extra operations.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Get Points Index from Rect
It seems to be working great enought for me.
There is my code so if others want to used it, be free to do so.
Thanks a lot again, i really appreciate your SuperFast Support!
There is my code so if others want to used it, be free to do so.
Code: Select all
Function GetPointsFromRect(AChart: TChart; ASerie: TChartSeries; ARect: TRect): TIntegerArray;
Var
Left, Right, Top, Bottom: Double;
Ctr: Integer;
Begin
If (ARect.Left > ARect.Right) Then Begin
Ctr := ARect.Left;
ARect.Left := ARect.Right;
ARect.Right := Ctr;
End;
If (ARect.Top > ARect.Bottom) Then Begin
Ctr := ARect.Top;
ARect.Top := ARect.Bottom;
ARect.Bottom := Ctr;
End;
//I assume that the serie is on the bottom and left axis.
Left := AChart.BottomAxis.CalcPosPoint(ARect.Left);
Right := AChart.BottomAxis.CalcPosPoint(ARect.Right);
Top := AChart.LeftAxis.CalcPosPoint(ARect.Top);
Bottom := AChart.LeftAxis.CalcPosPoint(ARect.Bottom);
SetLength(Result, 0);
For Ctr := 0 To ASerie.Count - 1 Do
If ((ASerie.XValues[Ctr] >= Left) AND (ASerie.XValues[Ctr] <= Right) AND (ASerie.YValues[Ctr] >= Bottom) AND (ASerie.YValues[Ctr] <= Top)) Then Begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := Ctr;
End;
End;
Re: Get Points Index from Rect
Hi GoToXY,
Thanks to your for your comments and for sharing!
Thanks to your for your comments and for sharing!
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |