If the line appears on the right side of the chart, I try to position the annotation so that it shifts right as not to cut off the text in the annotation--I even add margin for this. Here is my code for it:
Code: Select all
procedure SetLeftPos(aMiddle: double; aAnnTool: TAnnotationTool);
const
H_MARGIN = 50;
var
lLeft: Integer;
lR: TRect;
lAnnWidth: Integer;
begin
if not aAnnTool.Active then
exit;
lLeft := aChart.BottomAxis.CalcXPosValue(aMiddle);
lR := aAnnTool.Bounds;
lAnnWidth := lR.Right- lR.Left + 1;
aAnnTool.Shape.Left := lLeft - (Max(0, lAnnWidth) div 2);
if aAnnTool.Shape.Left + aAnnTool.Shape.Width > (aChart.Width - H_MARGIN) then
aAnnTool.Shape.Left := aChart.Width - H_MARGIN - aAnnTool.Shape.Width;
aAnnTool.Shape.Top := 30;
end;
I cannot figure out how to get this so it does not go off the right side of the chart. How can I achieve that?
A demo of this is attached.
Thank you,
Ed Dressel