clicked part for axis
clicked part for axis
im trying to get the clicked part for axis, im using CalcClickedPart function, it works but if i click on axis labels it wont trigger. also protected AxisRect function is returning rect excluding the label part, if you look at my screenshot, it will only work if i click on the axis line but it doesnt work when clicked on labels.
- Attachments
-
- Capture.PNG (1.51 KiB) Viewed 13898 times
Re: clicked part for axis
Hello,
This should allow you to determine when an axis label has been clicked:
This should allow you to determine when an axis label has been clicked:
Code: Select all
uses TeCanvas;
procedure TForm1.Chart1Click(Sender: TObject);
function RectOf(AAxis: TChartAxis; Index:Integer):TRect;
var tmpItem : TAxisItem;
tmp,
tmpW,
tmpH : Integer;
tmpP : TPoint;
begin
tmpItem:=AAxis.Items[Index];
tmp:=tmpItem.LabelPos;
tmpW:=AAxis.ParentChart.Canvas.TextWidth(tmpItem.Text);
tmpH:=AAxis.ParentChart.Canvas.FontHeight;
if AAxis.Horizontal then
begin
if AAxis.OtherSide then
begin
result.Bottom:=AAxis.PosLabels;
result.Top:=result.Bottom-tmpH;
end
else
begin
result.Top:=AAxis.PosLabels;
result.Bottom:=result.Top+tmpH;
end;
end
else
begin
if AAxis.OtherSide then
result.Left:=AAxis.PosLabels
else
result.Right:=AAxis.PosLabels;
end;
if AAxis.Horizontal then
begin
result.Left:=tmp-(tmpW div 2);
result.Right:=result.Left+tmpW;
end
else
begin
result.Top:=tmp-(tmpH div 2);
result.Bottom:=result.Top+tmpH;
if AAxis.OtherSide then
result.Right:=result.Left+tmpW
else
result.Left:=result.Right-tmpW
end;
if AAxis.ParentChart.View3D then
begin
tmpP:=AAxis.ParentChart.Canvas.Calculate3DPosition(result.TopLeft.X,result.TopLeft.Y,Round(AAxis.ParentChart.Width3D*AAxis.ZPosition*0.01));
OffsetRect(result,tmpP.X-result.Left,tmpP.Y-result.Top);
end;
end;
var i: Integer;
begin
with Chart1.Axes.Bottom do
begin
ParentChart.Canvas.AssignFont(Texts.Font);
for i:=0 to Items.Count-1 do
if PointInRect(RectOf(Chart1.Axes.Bottom, i), Chart1.GetCursorPos) then
ShowMessage('clicked label');
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: clicked part for axis
That method will get me the rect of each label, but i need to get the rect of Axis, just as shown below, if i use this method it will not trigger when user click on the gap between labels.
- Attachments
-
- Capture.png (1.77 KiB) Viewed 13857 times
Re: clicked part for axis
nevermind, i have managed to get the full rect based on first items left and last items right. thanks
Re: clicked part for axis
Hello,
I'm glad to hear you found how to achieve it.
I'm glad to hear you found how to achieve it.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |