OnHover event
OnHover event
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?
Re: OnHover event
Hello,
You can use the Chart's OnMouseMove event. Ie:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: OnHover event
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.
Re: OnHover event
Hello,
Find here a simple example you can take as starting point:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |