You can use Automation to programmatically rotate a graph. By using the
Rotation property, you can rotate a three-dimensional graph to change the viewpoint of a graph or to provide an animated effect.
To rotate a three-dimensional pie graph a full 360 degrees, follow these steps:
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
- Start Microsoft Access, and then open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
- Open a new, blank form in Design view.
- On the Insert menu, click Chart. Click and drag a chart to the form.
- In the first dialog box of the Chart Wizard, under View, click
Queries, and then select the Category Sales for 1997 query. Click Next.
- In the next dialog box, add the CategorySales and CategoryName fields to the Fields for Chart box. Click Next.
- In the next dialog box, click 3-D Pie Chart, and then click Finish. Your graph now appears on the form.
- On the View menu, click Properties. Select the graph so that you are viewing the Graph object's properties. Set the Name property to MyGraph.
- Add a command button to the form with the following properties:
Caption: Rotate Graph
OnClick: =RotateGraph()
- Click the form, and then, on the View menu, click Code to view the form's module.
- Add the following code to the form's module:
Function RotateGraph()
Dim OldRotation As Integer
Dim NewRotation As Integer
Dim GraphObj As Object
Set GraphObj = Me![MyGraph].Object.Application.Chart
' Determine the initial rotation setting.
OldRotation = GraphObj.Rotation
' Rotate graph from initial setting to 360 degrees.
For NewRotation = OldRotation To 360 Step 12
GraphObj.Rotation = NewRotation
If GraphObj.Rotation = 360 Then GraphObj.Rotation = 0
DoEvents
DoCmd.RepaintObject
Next
End Function
- Switch the form to Form view. Click the command button to make the graph rotate 360 degrees.