Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top