Page 1 of 1

Sensing series values

Posted: Fri Apr 04, 2008 2:50 pm
by 9235719
I have a chart on which there are say 8 series plotted, Series1, Series2,.....
Now I would like to mouseclick somewhere on the chart (not necessarily directly on a plotted series line), and automatically get the X value of say Series1.
Mike

Posted: Fri Apr 04, 2008 3:01 pm
by narcis
Hi Mike,

You could do something as in the example suggested here. Instead of the cursor tool event you could use the OnMouseDown event to retrieve the clicked XValue like this:

Code: Select all

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  XVal: double;
begin
  XVal:=Chart1.Axes.Bottom.CalcPosPoint(X);
  //Add the interpolating code here.
end; 

Sensing series

Posted: Fri Apr 04, 2008 3:07 pm
by 9235719
Thanks, that partially solves my problem, which I realise I hadnt explained properly. A series consists of a list of X,Y values, numbered from 1 to a max number of items. So what I would like to so is to click anywhere on the chart, and then return the item value from one of the series, say Series1, rather than the actual X value.
regards
Mike

Posted: Fri Apr 04, 2008 3:14 pm
by narcis
Hi Mike,

In that case and if I understood your request correctly you can do something like this:

Code: Select all

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  XVal: double;
  i, SeriesIndex: Integer;
begin
  for i:=Chart1.ChartRect.Top to Chart1.ChartRect.Bottom do
  begin
    SeriesIndex:=Chart1[0].Clicked(X, i);

    if SeriesIndex<>-1 then
    begin
      Chart1.Title.Text[0]:=FloatToStr(Chart1[0].XValue[SeriesIndex]) + ' - ' +
                            FloatToStr(Chart1[0].YValue[SeriesIndex]);
      break;
    end;
  end;
end;

sensing series

Posted: Fri Apr 04, 2008 3:23 pm
by 9235719
Thanks. That does it. Very clever! I didnt know about an instruction like
SeriesIndex:=Chart[0].Clicked(X, i);

all the best
Mike

Posted: Fri Apr 04, 2008 3:33 pm
by narcis
Hi Mike,

You're very welcome. I'm glad to hear that helped.

Yes, Clicked method is very useful and is available for several TeeChart objects (series, axes, legend, ...).

Have a nice weekend!