OnHover event

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
realsol
Newbie
Newbie
Posts: 70
Joined: Mon Feb 27, 2017 12:00 am

OnHover event

Post by realsol » Mon Dec 11, 2017 7:57 pm

I know that the chart and the legend react when the mouse hovers a slice. Right now, I let the user 'right-click' on the chart to display a slices value in a callout panel hint. I want this to happen automatically as they hover over the legend or slice. I have the STD license. Is there some way I can hook into that event?

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

Re: OnHover event

Post by Yeray » Tue Dec 12, 2017 9:18 am

Hello,

You can use the Chart's OnMouseMove event. Ie:

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
var ValueIndex: Integer;
begin
  ValueIndex:=Chart1.Legend.Clicked(Round(X),Round(Y));

  if ValueIndex=-1 then
  begin
    ValueIndex:=Series1.Clicked(X, Y);
  end;

  Caption:=IntToStr(ValueIndex);
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

realsol
Newbie
Newbie
Posts: 70
Joined: Mon Feb 27, 2017 12:00 am

Re: OnHover event

Post by realsol » Tue Dec 12, 2017 4:21 pm

Thanks. I will give it a shot. It there a % property for pie slices. I would like to popup the hint showing the total and the % of the pie. I would like to somehow wrap it in the code above.

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

Re: OnHover event

Post by Yeray » Wed Dec 13, 2017 8:32 am

Hello,

Find here a simple example you can take as starting point:

Code: Select all

uses Series;

var myValueIndex: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.AddSeries(TPieSeries).FillSampleValues;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
begin
  myValueIndex:=Chart1.Legend.Clicked(Round(X),Round(Y));

  if myValueIndex=-1 then
  begin
    myValueIndex:=Chart1[0].Clicked(X, Y);
  end;

  if myValueIndex>-1 then
     Chart1.Repaint;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var tmpX, tmpY, tmpW, tmpH: Single;
    tmpP: Double;
    tmpS: string;
begin
  if myValueIndex>-1 then
  begin
    tmpX:=Chart1.GetCursorPos.X;
    tmpY:=Chart1.GetCursorPos.Y;
    tmpP:=Chart1[0].YValue[myValueIndex]*100/Chart1[0].YValues.Total;
    tmpS:='ValueIndex: ' + IntToStr(myValueIndex) + sLineBreak +
          'Value: ' + FormatFloat(Chart1[0].ValueFormat, Chart1[0].YValue[myValueIndex]) + sLineBreak +
          'Percent: ' + FormatFloat('#0.## %', tmpP);

    with Chart1.Canvas do
    begin
      tmpW:=TextWidth(tmpS);
      tmpH:=TextHeight(tmpS);
      Rectangle(RectF(tmpX, tmpY, tmpx+tmpW, tmpY+tmpH), 0);
      TextOut(tmpX, tmpY, tmpS);
    end;
  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

realsol
Newbie
Newbie
Posts: 70
Joined: Mon Feb 27, 2017 12:00 am

Re: OnHover event

Post by realsol » Wed Dec 13, 2017 4:05 pm

Thank you.

Post Reply