Sensing series values

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Mike Glazer
Newbie
Newbie
Posts: 13
Joined: Mon Jan 24, 2005 5:00 am
Location: Oxford
Contact:

Sensing series values

Post by Mike Glazer » Fri Apr 04, 2008 2:50 pm

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

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

Post by Narcís » Fri Apr 04, 2008 3:01 pm

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; 
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

Mike Glazer
Newbie
Newbie
Posts: 13
Joined: Mon Jan 24, 2005 5:00 am
Location: Oxford
Contact:

Sensing series

Post by Mike Glazer » Fri Apr 04, 2008 3:07 pm

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

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

Post by Narcís » Fri Apr 04, 2008 3:14 pm

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;
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

Mike Glazer
Newbie
Newbie
Posts: 13
Joined: Mon Jan 24, 2005 5:00 am
Location: Oxford
Contact:

sensing series

Post by Mike Glazer » Fri Apr 04, 2008 3:23 pm

Thanks. That does it. Very clever! I didnt know about an instruction like
SeriesIndex:=Chart[0].Clicked(X, i);

all the best
Mike

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

Post by Narcís » Fri Apr 04, 2008 3:33 pm

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!
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