[SOLVED] Series OnClick Event Help needed

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
ChZiegelt
Newbie
Newbie
Posts: 39
Joined: Thu Aug 09, 2007 12:00 am
Contact:

[SOLVED] Series OnClick Event Help needed

Post by ChZiegelt » Mon Aug 27, 2007 7:07 pm

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 ?
Last edited by ChZiegelt on Tue Aug 28, 2007 11:41 am, edited 1 time in total.

bertrod
Advanced
Posts: 151
Joined: Wed Sep 07, 2005 4:00 am

Post by bertrod » Tue Aug 28, 2007 6:46 am

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 ;

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Aug 28, 2007 7:51 am

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:

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
Image Image Image Image Image Image
Instructions - How to post in this forum

ChZiegelt
Newbie
Newbie
Posts: 39
Joined: Thu Aug 09, 2007 12:00 am
Contact:

Post by ChZiegelt » Tue Aug 28, 2007 7:55 am

Thanks for your help so far,
I will try it out and report back if it worked for me !

ChZiegelt
Newbie
Newbie
Posts: 39
Joined: Thu Aug 09, 2007 12:00 am
Contact:

Post by ChZiegelt » Tue Aug 28, 2007 9:37 am

Finaly I managed to get what I neede :-)

Its not possible to use SeriesClicked() because you need to click on the series itself, if you click somewhere in the chart (which is what I need) the code wont work.
So I used your code in the ChartClicked() Method.

Thanks for the help !

ChZiegelt
Newbie
Newbie
Posts: 39
Joined: Thu Aug 09, 2007 12:00 am
Contact:

Post by ChZiegelt » Tue Aug 28, 2007 9:39 am

How do I mark the question as "answered " ?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Aug 28, 2007 9:47 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply