Next Tip  Changing The Way MS Graph Looks          Lesson 4

In this lesson, I will show you some of the visual basic code required to manipulate MSgraph

The following picture shows some of the properties that you can manipulate in the Chart OLE object.

mschart1.gif (19934 bytes)

First we will look at a declaration that I made in the Form_Load event to make referencing easier  

Private Sub Form_Load()
' Define an object so that reference can be used throughout the form

  Set MyGrafObj = Me![chart1].object.Application.Chart

end sub    

'  Note I tried this again later and the object was called me![OLE1] so watch for the object name   ED

To add a text string to the title of the graph,  I have added a button at the bottom of the form. 

Private Sub cmdAddTitle_Click()

' Toggle the title on and off

  With MyGrafObj
    .HasTitle = Not .HasTitle

    If .HasTitle Then

'      Display the title
      .ChartTitle.Text = CStr(Me!MainTitle)
    End If
  End With
End Sub

To change the styles of the graph, try the following  to change the form to Cylinders as above or maybe stacked 3D bars.    

Private Sub BarSt_Click()

  MyGrafObj.ChartType = xlCylinderCol
End Sub

Private Sub BarSt3D_Click()
  MyGrafObj.ChartType = xl3DBarStacked
End Sub

Some of the other constants that you can use for the graph are show in the table below

ChartType

97 Constant
Bar xlBarClustered
Stacked Bar xlBarStacked
Line xlLine
3d Line xl3DLine
Area xlAreaStacked
3D Area xl3DAreaStacked
Column xColumnClustered
3D Column xl3DColumn
Pie xlPie
3D Pie xl3DPie

To toggle the graphs legend on and off, try the following

Private Sub tglLegend_Click()

' Toggle the legend
  With MyGrafObj

    .HasLegend = Not .HasLegend
  End With
End Sub

And to complete the lesson off, I have added  horisontal and vertical slider bars to the form so that you can rotate and tilt 3D Graphs.  The code for the horizontal rotation is as follows

Private Sub grafRotate_Click()

On Error GoTo grafRotate_error

  With MyGrafObj
    .Rotation = Me!grafRotate
  End With

  Exit Sub

grafRotate_error:

  MsgBox "This graf does not support rotations ... " & Error, vbInformation, "Try Another Graph"
  Exit Sub

End Sub

graphspin.gif (10776 bytes)

 

  Click here for the download file if you own "The Toolshed"  Else click here 

 

Links >>>  Home | Search | Workbench | Orders | Newsletter | Access Security | Access professionals