Axis on origin

TeeChart for ActiveX, COM and ASP
Post Reply
ACC
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Axis on origin

Post by ACC » Thu Feb 23, 2006 3:54 pm

Is it possible to set the axes at a defined point?

Eg. I want the axes in the center of the chart, at point (0, 0) of a particular serie, ala Cartesian axes.

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Feb 23, 2006 4:04 pm

Hi ACC,

Yes, you can easily get that by doing:

Code: Select all

Private Sub Form_Load()
    TChart1.Series(0).FillSampleValues 10
    
    With TChart1.Axis
        .Left.PositionUnits = puPercent
        .Left.PositionPercent = 50
        .Bottom.PositionUnits = puPercent
        .Bottom.PositionPercent = 50
    End With
End Sub
Best Regards,
Narcís Calvet / 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

ACC
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Post by ACC » Thu Feb 23, 2006 7:30 pm

The problem is that I don't control the data, so the origin may be on other position than the center of the chart. I want the axes to be parallel to the value 0 (or any other defined).

Regards,

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Mar 13, 2006 2:24 pm

Hi ACC,

There are a couple of ways to do that (enable or disable usePercentages) as done here:

Code: Select all

Private Sub Form_Load()
    For i = -5 To 10
        TChart1.Series(0).AddXY i, i, "", clTeeColor
    Next i
    
    TChart1.Panel.MarginUnits = muPixels
    
    TChart1.Environment.InternalRepaint
End Sub

Private Sub TChart1_OnAfterDraw()
  With TChart1.Axis
    
    If usePercentages = True Then
        
         chartWidth = .Right.Position - .Left.Position
         horizZeroLoc = .Bottom.CalcXPosValue(0) - .Left.Position
         horizPercentLoc = horizZeroLoc / chartWidth * 100

        .Left.PositionUnits = puPercent
        .Left.PositionPercent = horizPercentLoc

         chartHeight = .Bottom.Position - .Top.Position
         vertZeroLoc = .Left.CalcYPosValue(0) - .Top.Position
         vertPercentLoc = vertZeroLoc / chartHeight * 100

        .Bottom.PositionUnits = puPercent
        .Bottom.PositionPercent = 100 - vertPercentLoc
        
    Else
        
        .Left.PositionUnits = puPixels
        .Left.PositionPercent = .Bottom.CalcXPosValue(0) - .Left.Position
        
        .Bottom.PositionUnits = puPixels
        .Bottom.PositionPercent = .Bottom.Position - .Left.CalcYPosValue(0)
                              
    End If
    
  End With
End Sub
Best Regards,
Narcís Calvet / 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