Page 1 of 1

[SOLVED] Series OnClick Event Help needed

Posted: Mon Aug 27, 2007 7:07 pm
by 10546441
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 ?

Posted: Tue Aug 28, 2007 6:46 am
by 9343260
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 ;

Posted: Tue Aug 28, 2007 7:51 am
by narcis
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;

Posted: Tue Aug 28, 2007 7:55 am
by 10546441
Thanks for your help so far,
I will try it out and report back if it worked for me !

Posted: Tue Aug 28, 2007 9:37 am
by 10546441
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 !

Posted: Tue Aug 28, 2007 9:39 am
by 10546441
How do I mark the question as "answered " ?

Posted: Tue Aug 28, 2007 9:47 am
by narcis
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.