Page 1 of 1

customize scale labels

Posted: Mon Mar 24, 2008 8:29 pm
by 15047998
Hi,

Does anybody have some experience in customizing scale labels? All I want to do is to make the most left x-sxale label left-bound - the most right bound label right bound - and keep all the other labels centered for multiscaled X-axis

How do I get it working also in zoom mode?

Thanks,
huh

Posted: Tue Mar 25, 2008 1:00 pm
by narcis
Hi hugh,

Yes, you can do something like this:

Code: Select all

Private Sub Form_Load()
With TChart1.Series(0)
    .Clear
    .Add 123, "First", clTeeColor
    .Add 456, "Second", clTeeColor
    .Add 321, "Third", clTeeColor
    .Add 234, "Last", clTeeColor
End With
End Sub


Private Sub TChart1_OnDrawAxisLabel(ByVal Axis As Long, ByVal X As Long, ByVal Y As Long, LabelText As String)
With TChart1
  If Axis = 0 Then
    If X = TChart1.Axis.Bottom.CalcXPosValue(TChart1.Axis.Bottom.Minimum) Then
       .Canvas.Font.Bold = True
       .Canvas.TextAlign = ctaLeft
    Else
      If X = TChart1.Axis.Bottom.CalcXPosValue(TChart1.Axis.Bottom.Maximum) Then ' // last label
       .Canvas.Font.Bold = True
       .Canvas.TextAlign = ctaRight
      Else
       .Canvas.Font.Bold = False
      End If
    End If
  End If
End With
End Sub

customize scale labels

Posted: Tue Mar 25, 2008 1:58 pm
by 15047998
Thanks, Narcis

That works great for full scale - however how can I do the same while zooming - this way the maximum and minumum value comparison does not work anymore - How can I identify the first and last value to be modified while zooming?

Thanks,

Hugh

Posted: Thu Mar 27, 2008 10:16 am
by narcis
Hi Hugh,

You can do something like this:

Code: Select all

Private Sub Form_Load()
    With TChart1.Series(0)
        .Clear
        .Add 123, "First", clTeeColor
        .Add 456, "Second", clTeeColor
        .Add 321, "Third", clTeeColor
        .Add 234, "Last", clTeeColor
    End With
End Sub

Private Sub TChart1_OnDrawAxisLabel(ByVal Axis As Long, ByVal X As Long, ByVal Y As Long, LabelText As String)
    With TChart1
      If Axis = 0 Then
        If X = TChart1.Axis.Bottom.CalcXPosValue(TChart1.Axis.Bottom.Minimum) Then
           .Canvas.Font.Bold = True
           .Canvas.TextAlign = ctaLeft
        Else
          If X = TChart1.Axis.Bottom.CalcXPosValue(TChart1.Axis.Bottom.Maximum) Then ' // last label
           .Canvas.Font.Bold = True
           .Canvas.TextAlign = ctaRight
          Else
           .Canvas.Font.Bold = False
          End If
        End If
      End If
    End With
End Sub

Private Sub TChart1_OnZoom()
    TChart1.Environment.InternalRepaint
    
    With TChart1.Axis.Bottom
        .Labels.Clear
        
        For i = .Minimum To .Maximum
            .Labels.Add i, CStr(i)
        Next
        
        .Labels.Add .Maximum, CStr(.Maximum)
    End With
End Sub
For original labels to be restored when unzooming you'll be able to use the code below in the next v8 maintenance release:

Code: Select all

Private Sub TChart1_OnUndoZoom()    
    TChart1.Axis.Bottom.Labels.Automatic = True
    TChart1.Repaint
End Sub
If you are interested on that feature we can send you the .ocx with this new feature included.

Posted: Tue Apr 01, 2008 2:07 pm
by 15047998
Hi Narcis,

Yes - I would like to try the new ocx -

Thanks,

Gerhard

Posted: Tue Apr 01, 2008 2:40 pm
by narcis
Hi hugh,

Ok, I'll send you an e-mail with the URL to download it.

Remember you'll need to unregister old .ocx and register new one as described on this thread.