Custom Text - Alignment

TeeChart for ActiveX, COM and ASP
Post Reply
Kaprice
Newbie
Newbie
Posts: 11
Joined: Wed Aug 14, 2013 12:00 am

Custom Text - Alignment

Post by Kaprice » Wed Oct 09, 2013 9:26 pm

I'm using this code to add custom text to my chart:

Code: Select all

      .Tools.Add tcAnnotate
      With .Tools.Items(ctr - 1)
          .Active = True
          With .asAnnotation
            .Top = (intRecTop + 5) + (intTextHeight * (ctr - 1))
            .Left = intRecLeft
            
            
            With .Shape
              .TextAlignment = taRightJustify
              .Transparent = True
              .Transparency = 100
              .ShapeStyle = fosSquareRectangle
              .Font.Color = vbBlue
            End With
            .Text = Format(macurMoTotals(ctr), "$#,##0")
          End With
      End With
This is in a loop that adds 3 lines (each in separate shapes).

I'm trying to get them to Right Align with each other, but the above code does not do that. I also tried moving .TextAlignment = taRightJustify above the .shape block, but that doesn't work, either.

How can I fix this code -- or is there a better way, entirely, to add 3 lines of numbers to the chart and have the numbers right aligned to each other?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Custom Text - Alignment

Post by Sandra » Thu Oct 10, 2013 2:37 pm

Hello Kaprice,

I have modified your code, because works for me and I have achieved align the Annotation tool to the Right and its text, too, repainting the Chart with method Environment.InternalRepaint. Please see next code and try to do something similar in your application.

Code: Select all

Private Sub Form_Load()
   TChart1.Aspect.View3D = False
   TChart1.AddSeries scFastLine
   TChart1.Series(0).FillSampleValues
   Dim intRectTop, intRectLeft As Integer
   Dim i As Integer
   For i = 0 To 2
        With TChart1
            .Tools.Add tcAnnotate
            .Environment.InternalRepaint
            With .Tools.Items(i)
                 .Active = True
                 With .asAnnotation
                   .Left = .Left + intRectLeft
                   .TextAlignment = ARight
                    intRectLeft = .Left + 10
                    
                    With .Shape
                        .Transparent = True
                        .ShapeStyle = fosSquareRectangle
                        .Font.Color = vbBlue
                   End With
                 End With
            End With
            .Tools.Items(i).asAnnotation.Text = Str(i)
      End With
   Next i
End Sub
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply