Page 1 of 1

Axis on origin

Posted: Thu Feb 23, 2006 3:54 pm
by 9528872
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.

Posted: Thu Feb 23, 2006 4:04 pm
by narcis
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

Posted: Thu Feb 23, 2006 7:30 pm
by 9528872
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,

Posted: Mon Mar 13, 2006 2:24 pm
by narcis
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