views:

908

answers:

2

I'm using the TChart control that comes with Delphi 7 and wish to get the Series and Value # of the line/bar under the mouse pointer.

I'm aware of the OnClickSeries event which provides great info but I really want this info when I hover over a series.

EDIT: I found a hittest method on TChart which works with any series types and multiple series in the one chart so I've posted this and made it my accepted answer. Special Thanks to GameCat for his effort.

+4  A: 

You can check the OnChartMouseMove (or the OnSeriesMouseMove)

procedure TForm5.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  i : Integer;
begin
  i := Series1.CalcClickedPie(x,y); // i = index of checked data -1 for none
  Memo1.Lines.Add(IntToStr(i));
end;

Ok, my bad, the code for bars is different (even easier):

procedure TForm5.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  i : Integer;
begin
  i := Series1.GetCursorValueIndex;
  Memo1.Lines.Add(IntToStr(i));
end;
Gamecat
Thanks. Though I'm really after getting the series/value at a point in a Bar/Line chart.
Ben Daniel
It shouldn't be that different for other series.
Gamecat
Hehe, I totally agree they *shouldn't* be that different to other series - though I've been unable to find anything similar.
Ben Daniel
Added bar example, it is a mystery why those have to be different.
Gamecat
Dude, +1 for all the effort you put into this question. I eventually found a method which is exactly what I wanted so I've made it my answer but wish I could give you +10 for your help. Cheers heaps. :)
Ben Daniel
+1  A: 

I finally found this method which works with multiple series (even of different types) in a chart.

TChart.CalcClickedPart(Pos: TPoint; Var Part: TChartClickedPart);

The method fills a TChartClickedPart record which contains the following detailed hit-test information:

TChartClickedPart = record
  Part : TChartClickedPartStyle;
  PointIndex : Integer;
  ASeries : TChartSeries;
  AAxis : TChartAxis;
end;

This includes the Series and the ValueIndex (PointIndex) which is exactly what I wanted.

Ben Daniel