How can I link plot names for all plots in my Grapher graph to worksheet cells?

By default, Grapher 14 Preview names new plots based on the value in the first row of the Y column.  If your header values are not in row 1 or you are running an earlier release of Grapher, the plot names are not directly linked to any worksheet data.  However, the script below can be used to name the plot based on a specified variable (Y) column.  

To run this script:

  1. Click here to download the BAS file: NamePlots.BAS.
  2. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
  3. Click the Open () icon in the Script Manager, select the downloaded BAS file, and click Open.
  4. Click File | Open, select your Grapher project, and click Open.
  5. On Line 18 of the script, edit the datafile path to define the worksheet used to create your plots.
  6. On Line 19, define the shift variable such that 1+shift is equal to the first variable (Y) column.  For example a shift of 1 would define column B as the first variable column.
  7. Click the Start/Resume () icon in the Script Manager.

OR:

  1. Copy the script below.
  2. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
  3. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
  4. Press Ctrl+V to paste it into the Script Manager.
  5. Click File | Open, select your Grapher project, and click Open.
  6. On Line 18 of the script, edit the datafile path to define the worksheet used to create your plots.
  7. On Line 19, define the shift variable such that 1+shift is equal to the first variable (Y) column.  For example a shift of 1 would define column B as the first variable column.
  8. Click the Start/Resume icon () in the Script Manager. 

'=================================================
'1. Open a Grapher file with one graph containing many plots from a single data file.
'2. Define the datafile that these plots were created from (line 18).
'3. Define a shift such that 1+shift=first variable column number (line 19)
'   (i.e. if first variable col is B [2], shift=1).
'4. Script changes the plot names to the variable name from the header row.
'=================================================
Sub Main

'Initializes Grapher
Dim Grapher As Object
Set Grapher = CreateObject("Grapher.Application")
Grapher.Visible = True

'=============================
'User-defined variables
'-----------------------------
datafile="C:\program files\golden software\grapher 12\samples\3D bar chart.dat"
shift = 1 'Number to add to 1 to get to the first variable column
'=============================

'Defines the active plot window and opens the desired data file in the worksheet
Set Plot1 = Grapher.Documents.Active
Set Data = Grapher.Documents.Open(datafile)

'Defines the Graph object
Set Graph1 = Plot1.Shapes.Item(1)

'Loops through all of the plots, setting the plot names to the header row from the data
For i=1 To Graph1.Plots.Count
	Data.Activate
	Data.Cells(1,i+shift).Copy()
	Plot1.Activate
    Graph1.Plots.Item(i).Name = Clipboard$()
Next i

End Sub

 

Updated October 16, 2018

Was this article helpful?
1 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.