Get MouseOver when mouse is over a mark

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Mandi Nice
Newbie
Newbie
Posts: 3
Joined: Fri Dec 07, 2007 12:00 am

Get MouseOver when mouse is over a mark

Post by Mandi Nice » Mon Jul 13, 2009 7:00 pm

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

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Get MouseOver when mouse is over a mark

Post by Yeray » Tue Jul 14, 2009 9:30 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply