This article contains a sample script for looping through all axes in the graph and making a change.
-
To run this script:
- Click here to download the BAS file: Loop through and change all axes.BAS.
- Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.
OR:
- Copy the script below.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
- Press Ctrl+V to paste it into the Script Manager.
- Click the Start/Resume icon () in the Script Manager.
*********
Sub Main 'Declares GrapherApp as an Object Dim GrapherApp As Object 'Start Grapher Set GrapherApp = CreateObject("Grapher.Application") 'Make the Grapher window visible GrapherApp.Visible = True 'Open the bar chart orientations.grf sample file Set Plot1 = GrapherApp.Documents.Open(GrapherApp.Path+"\Samples\bar chart orientations.gpj") 'Loop through and find only graphs For i = 1 To Plot1.Shapes.Count If Plot1.Shapes.Item(i).Type = grfShapeGraph Then 'Once you find a graph, loop through and find only axes For j = 1 To Plot1.Shapes.Item(i).Axes.Count 'Once you find an axis, see if it is an X Axis If Plot1.Shapes.Item(i).Axes.Item(j).axisType = grfXAxis Then 'If it is an X Axis, change the min and max values - these can be values that are previously set to a variable Plot1.Shapes.Item(i).Axes.Item(j).AutoMin = False Plot1.Shapes.Item(i).Axes.Item(j).AutoMax = False Plot1.Shapes.Item(i).Axes.Item(j).Min = 3 Plot1.Shapes.Item(i).Axes.Item(j).Max = 28 'Change the label format Plot1.Shapes.Item(i).Axes.Item(j).TickLabels.MajorFormat.DateTimeFormat = 5 End If 'Find the next axis Next j End If 'Find the next graph Next i End Sub
Updated October 15, 2018
Comments
Please sign in to leave a comment.