Hi Steema,
I am new to the TAnnotationTool but I have found an interesting problem. If I use the following code it works fine.
TMYForm.FormCreate ;
begin
SetLength(SieveAnnotation,12) ;
for i := 0 to 11 do
begin
SieveAnnotation := TAnnotationTool.Create(self) ;
SieveAnnotation.Brush.Color:=clWhite;
SieveAnnotation.Shape.Transparency:=0;
if i = 0 then
SieveAnnotation.Text:='COBBLES';
if i = 1 then
SieveAnnotation.Text:='COARSE GRAVEL';
if i = 2 then
SieveAnnotation.Text:='MEDIUM GRAVEL';
if i = 3 then
SieveAnnotation.Text:='FINE GRAVEL';
if i = 4 then
SieveAnnotation.Text:='COARSE SAND';
if i = 5 then
SieveAnnotation.Text:='MEDIUM SAND';
if i = 6 then
SieveAnnotation.Text:='FINE SAND';
if i = 7 then
SieveAnnotation[i].Text:='COARSE SILT';
if i = 8 then
SieveAnnotation[i].Text:='MEDIUM SILT';
if i = 9 then
SieveAnnotation[i].Text:='FINE SILT';
if i = 10 then
SieveAnnotation[i].Text:='CLAY';
end;
for i := 0 to 10 do
begin
SieveAnnotation[i].Active := true ;
chPSD1.Tools.Add(SieveAnnotation[i]);
end;
end;
TMyForm.chPSD1AfterDraw(Sender: TObject);
begin
With chPSD1 do
Begin
LeftVal := chPSD1.BottomAxis.CalcPosValue(60) ;
TopVal := chPSD1.LeftAxis.IStartPos - 15 ;
RightVal := chPSD1.BottomAxis.IEndPos;
BottomVal := chPSD1.LeftAxis.IStartPos ;
SieveAnnotation[0].PositionUnits:=muPixels;
// SieveAnnotation[0].Shape.AutoSize := false ;
SieveAnnotation[0].Shape.Left:=LeftVal;
SieveAnnotation[0].Shape.Top:=TopVal;
SieveAnnotation[0].Shape.Width:=RightVal-LeftVal;
SieveAnnotation[0].Shape.Height:=TopVal-BottomVal;
end;
If I use the code above then it works fine. However if I uncomment the line in the AfterDraw procedure then it only shows me blank boxes but they are the correct width. My bottomaxis is also Logarithmic if that helps.
Can you shed any light for me on what is going wrong here ?
Dynamic TAnnotationTool Autosize=false makes text disappear?
Hi swesty,
The problem is that you are setting a negative value to the annotation's Shape.Height so the rectangle is painted just above the text and the text without its rectangle isn't drawn.
You could correct your Shape.Height calculations in order to ensure that it has a positive value or you could call the TeCanvas OrientRectangle function that does the same:
Finally I'd like to suggest you a pair of things:
1. You don't need to set some properties (PositionUnits, Shape.AutoSize) at OnAfterDraw event as they will be re-set again and again.
2. Chart's BottomAxis, LeftAxis,... properties are deprecated properties. I recommend you to use Chart's Axes.Bottom, Axes.Left,...
The problem is that you are setting a negative value to the annotation's Shape.Height so the rectangle is painted just above the text and the text without its rectangle isn't drawn.
You could correct your Shape.Height calculations in order to ensure that it has a positive value or you could call the TeCanvas OrientRectangle function that does the same:
Code: Select all
uses TeCanvas;
//...
Annotation.Shape.ShapeBounds := OrientRectangle(Annotation.Shape.ShapeBounds);
1. You don't need to set some properties (PositionUnits, Shape.AutoSize) at OnAfterDraw event as they will be re-set again and again.
2. Chart's BottomAxis, LeftAxis,... properties are deprecated properties. I recommend you to use Chart's Axes.Bottom, Axes.Left,...
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Hi Yeray,
Thanks so much for the information.
I must admit with the first point you have noted I basically copied code from a previous forum article and that's why PositionUnits is in the AfterDraw because that is what was suggested. The forum article I am referring to is http://www.teechart.net/support/viewtopic.php?t=3502 which as you can see does it the way I have listed. But that's ok I can change to suit your recommendation.
Thanks for the tip on the Axes.....I have been using TChart for a long time and need to change my habits.
Cheers,
Steve
Thanks so much for the information.
I must admit with the first point you have noted I basically copied code from a previous forum article and that's why PositionUnits is in the AfterDraw because that is what was suggested. The forum article I am referring to is http://www.teechart.net/support/viewtopic.php?t=3502 which as you can see does it the way I have listed. But that's ok I can change to suit your recommendation.
Thanks for the tip on the Axes.....I have been using TChart for a long time and need to change my habits.
Cheers,
Steve