Page 1 of 1
clicked part for axis
Posted: Thu Jan 14, 2016 2:22 am
by 16577003
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.
Re: clicked part for axis
Posted: Thu Jan 14, 2016 5:01 pm
by yeray
Hello,
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;
Re: clicked part for axis
Posted: Fri Jan 15, 2016 2:52 am
by 16577003
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.
Re: clicked part for axis
Posted: Fri Jan 15, 2016 6:13 am
by 16577003
nevermind, i have managed to get the full rect based on first items left and last items right. thanks
Re: clicked part for axis
Posted: Fri Jan 15, 2016 9:27 am
by yeray
Hello,
I'm glad to hear you found how to achieve it.