There is the following situation:
I have one series of measurement values in a chart (lineSeries) and I need to click anywhere in the chart - not only exact the point where the value is at.
No I want to receive the Index of the value of the nearest value.
But: I am only interested in the nearest values looking at the x axis.
Is there any function which could be of help to me, or do I have to parse the values and their rendered position by hand ?
[SOLVED] Series OnClick Event Help needed
[SOLVED] Series OnClick Event Help needed
Last edited by ChZiegelt on Tue Aug 28, 2007 11:41 am, edited 1 time in total.
I don't know if it's the best answer, but you can try this :
Code: Select all
value : real ;
i, index : integer ;
value := Chart.BottomAxis.CalcPosPoint(X) ; //find the value of the clicked point
for i := 0 to Series.count-1 do
if Series.XValues[i] >= value then
begin
index := i ; //find the index in the series
break ;
end ;
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi bertrod,
Thank you very much for your suggestion. However, it may be much easier using NearestPoint tool (TNearestTool) which already includes methods for that, for example:
Thank you very much for your suggestion. However, it may be much easier using NearestPoint tool (TNearestTool) which already includes methods for that, for example:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
ChartTool1.Active:=false;
Series1.FillSampleValues();
end;
procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var index: Integer;
begin
index:=ChartTool1.GetNearestPoint(Sender,X,Y);
ShowMessage(IntToStr(index));
end;
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 |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi ChZiegelt,
You can add a new subject for each message in the thread. You can also edit your original message subject and add something like [Solved], [Answered] or [Closed]; before the original subject.
Thanks in advance.
You can add a new subject for each message in the thread. You can also edit your original message subject and add something like [Solved], [Answered] or [Closed]; before the original subject.
Thanks in advance.
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 |