Follow

How do I edit my graph axis in Grapher via automation?

This article contains Grapher sample script that shows how to open a graph and alter an existing regular axis.

 

To run this script:

  1. Copy the script below, or click here to download the BAS file: axis properties.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Grapher 12\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.
     

*********

Sub Main
'This script shows many of the methods and properties of an axis

'Declares GrapherApp as an Object
Dim GrapherApp As Object

'Start Grapher
Set GrapherApp = CreateObject("Grapher.Application")

'Make the Grapher window visible
GrapherApp.Visible = True

'Create a new document window
Set Plot1 = GrapherApp.Documents.Add(grfPlotDoc)

'Create function plot graph named Graph1
Set Graph1 = Plot1.Shapes.AddFunctionPlotGraph(False,"cos(X)",,0,12)

'Set the function plot to the name FunctionPlot1
Set FunctionPlot1 = Graph1.Plots.Item(1)

'Name the X Axis "XAxis1"
Set XAxis1 = Graph1.Axes.Item(1)

'Change the Length to 8 inches
XAxis1.length = 8

'Move the X Axis to the top of the Y Axis
XAxis1.PositionAxis(grfPositionRightTop, "Y Axis 1")

'Set the Minimum X axis value to 1
XAxis1.AutoMin = False
XAxis1.Min = 1

'Set the Maximum X Axis value to 10
XAxis1.AutoMax = False
XAxis1.Max = 10

'Add an X Axis title that is red, size 16 font, and on the top of the axis
XAxis1.title.text = "Axis title"
XAxis1.title.Font.color = grfColorRed
XAxis1.title.Font.size = 16
XAxis1.title.Side = grfAxisTitleRightTop
XAxis1.title.yOffset = 0.2

'Show 0.04 inch red grid lines AtMajorTicks
XAxis1.Grid.AtMajorTicks = True
XAxis1.Grid.MajorLine.foreColor = grfColorRed
XAxis1.Grid.MajorLine.width = 0.04

'Show the tick marks on the right side
XAxis1.Tickmarks.MajorSide = grfTicksTopRight

'Set the TickMarks Spacing to 1
XAxis1.Tickmarks.MajorSpacingAuto = False
XAxis1.Tickmarks.MajorSpacing = 1

'Set the TickMarks MajorLength to 0.1 inches
XAxis1.Tickmarks.MajorLength = 0.1

'Set the TickMarks MajorLine color to blue
XAxis1.Tickmarks.MajorLineAuto = False
XAxis1.Tickmarks.MajorLine.foreColor = grfColorBlue

'Set the minor tick marks to the top and 5 divisions
XAxis1.Tickmarks.MinorSide = grfTicksTopRight
XAxis1.Tickmarks.MinorDivision = 5

'Set the TickLabels to show on the top side
XAxis1.TickLabels.MajorSide = grfTicksTopRight

'Set the TickLabels Frequency to 2 (every other)
XAxis1.TickLabels.MajorFreq = 2

'Set the TickLabels LabelDivisor to 10
XAxis1.TickLabels.LabelDivisor = 10

'Add an axis break with fixed scale
XAxis1.AxisBreak.on = True
XAxis1.AxisBreak.FixedScale = True

'Make the line color green and 0.04 inches wide
XAxis1.line.foreColor = grfColorGreen
XAxis1.line.width = 0.04

End Sub

 

Updated September 22, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.