Follow

How can I use a script to create a graph from a Grapher template?

This article contains a sample script for creating a graph from a template and adding information from the worksheet to the graph.

To run this script:

  1. Copy the script below, or click download the attached BAS file: text and values from worksheet.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.
     

*********

The HTML Clipboard
Sub Main
'Declare the variable that references the application
 Dim GrapherApp As Object

 'Creates an instance of the Grapher Application object
 'and assigns it to the variable named "GrapherApp"
 Set GrapherApp = CreateObject("Grapher.Application")

 'Make Grapher visible
 GrapherApp.Visible = True

 'Assigns the Documents collection to the variable named "Docs"
 Set Docs = GrapherApp.Documents

 'Defines the files to work with
 datafile$ = GrapherApp.Path+"\samples\tutorial.dat"
 template$ = GrapherApp.Path+"\templates\line scatter plot.grt"

 'Open the worksheet
 Set Wks = Docs.Open(datafile$)

 'Read the contents of a cell for text
 Text1 = Wks.Cells("A1")

 'Read the contents of a cell for Y axis maximum value
 WksYMax = Wks.Cells("B9").Value

 'Creates a new plot window and assign it to the variable named "Plot"
 Set Plot = Docs.Add(grfPlotDoc,template$,datafile$)

'Add text read from the text string in the worksheet
Plot.Shapes.AddText(2.5,6,Text1)

'Sets variables for Y Axis 1 and X Axis 1
Set YAxis1 = Plot.Shapes.Item("Graph 1").Axes.Item("Y Axis 1")
Set XAxis1 = Plot.Shapes.Item("Graph 1").Axes.Item("X Axis 1")

'Change the Y axis maximum based on the worksheet value
YAxis1.AutoMax = False
YAxis1.Max = WksYMax

'Updates the worksheet for the linked text axis titles
XAxis1.title.worksheet = datafile$
YAxis1.title.worksheet = datafile$

'Set TickLabels.MajorFormat.NumDigits
XAxis1.TickLabels.MajorFormat.NumDigits = 0

'Adjusts the TickMarks major spacing
XAxis1.Tickmarks.MajorSpacingAuto = False
XAxis1.Tickmarks.MajorSpacing = 1

'Set TickMarks.MinorSide
XAxis1.Tickmarks.MinorSide = grfTicksOff

End Sub

 

Updated October 28, 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.