How To Change the Axis Label Font and the Font Size in MSChart

Article translations Article translations
Article ID: 277712 - View products that this article applies to.
This article was previously published under Q277712
Expand all | Collapse all

On This Page

SUMMARY

When you work with the MSChart control, you can change the font or font size programmatically with the Labels collection of each axis.

MORE INFORMATION

The following code changes the font and font size for both axes of an MSChart object.

Step-by-Step Example

  1. Open a new Standard EXE project in Visual Basic 6.0. Form1 is created by default.
  2. On the Project menu, select Components to bring up the Components dialog box. Check Microsoft Chart Control, and then click OK.
  3. Add a CommandButton control and an MSChart control to Form1.
  4. Add the following code to the code window of Form1
    Private Sub Command1_Click()
        ' Note that MSChart20Lib is for Visual Basic 6.0
        ' it should be MSChartLib in Visual Basic 5.0
        Dim currentaxis As MSChart20Lib.Axis
        Dim currentlabel As MSChart20Lib.Label
        ' Get a reference to the x axis
        Set currentaxis = MSChart1.Plot.Axis(VtChAxisIdX)
        ' Loop though and set the font of each label
        For Each currentlabel In currentaxis.Labels
            currentlabel.VtFont.Name = "Courier"
            currentlabel.VtFont.Size = 16
        Next currentlabel
        ' get a reference to the y axis
        Set currentaxis = MSChart1.Plot.Axis(VtChAxisIdY)
        ' loop through and set the font of each label
        For Each currentlabel In currentaxis.Labels
            currentlabel.VtFont.Name = "Courier"
            currentlabel.VtFont.Size = 16
        Next currentlabel
    End Sub
    					
  5. Run the project, and note the font for the axis labels.
  6. Click on Command1, and note that the font changes.

Properties

Article ID: 277712 - Last Review: June 29, 2004 - Revision: 1.1
APPLIES TO
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
Keywords: 
kbhowto kbcodesnippet kbctrl KB277712

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com