Page 1 of 1
Get MouseOver when mouse is over a mark
Posted: Mon Jul 13, 2009 7:00 pm
by 10047643
Hi
How to find out when mouse is over an mark and get information which chart and which data point.
I only show the mark of the series and I want to show an hint when mouse is over an mark.
There should show a sepperate hint for each mark.
many thanks for helping.
Best Regards
Mandi
Re: Get MouseOver when mouse is over a mark
Posted: Tue Jul 14, 2009 9:30 am
by yeray
Hi Mandi,
You could do something like in the following example:
Code: Select all
uses series, TeeTools;
var series1: TBarSeries;
annotation1: TAnnotationTool;
procedure TForm1.FormCreate(Sender: TObject);
begin
series1 := TBarSeries.Create(self);
Chart1.AddSeries(series1);
series1.FillSampleValues(6);
annotation1 := TAnnotationTool.Create(self);
Chart1.Tools.Add(annotation1);
annotation1.Active := false;
Chart1.Draw;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var i, j: Integer;
p: TPoint;
r: TRect;
begin
p.X := X;
p.Y := Y;
for i:=0 to Chart1.SeriesCount-1 do
for j:=0 to Chart1[i].Count-1 do
begin
r.Left := Chart1[i].Marks.Positions[j].LeftTop.X;
r.Top := Chart1[i].Marks.Positions[j].LeftTop.Y;
r.Right := Chart1[i].Marks.Positions[j].LeftTop.X + Chart1[i].Marks.Positions[j].Width;
r.Bottom := Chart1[i].Marks.Positions[j].LeftTop.Y + Chart1[i].Marks.Positions[j].Height;
if PtInRect(r, p) then
begin
annotation1.Left := r.Right + 5;
annotation1.Top := r.Top;
annotation1.Text := 'value number ' + inttostr(j);
annotation1.Active := True;
Exit;
end
else
annotation1.Active := False;
end;
end;