How To Change the Axis Label Font and the Font Size in MSChart
This article was previously published under Q277712
This article has been archived. It is offered "as is" and will no longer be updated.
When you work with the MSChart control, you can change the font or font size programmatically with the Labels collection of each axis.
The following code changes the font and font size for both axes of an MSChart object.
- Open a new Standard EXE project in Visual Basic 6.0. Form1 is created by default.
- On the Project menu, select Components to bring up the Components dialog box. Check Microsoft Chart Control, and then click OK.
- Add a CommandButton control and an MSChart control to Form1.
- 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 currentlabelEnd Sub
- Run the project, and note the font for the axis labels.
- Click on Command1, and note that the font changes.
Article ID: 277712 - Last Review: 12/05/2015 22:27:33 - Revision: 1.1
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
- kbnosurvey kbarchive kbhowto kbcodesnippet kbctrl KB277712