Follow

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

There is not a direct way from the user-interface to link plot names to worksheet cells, but you can get this result by running the script below. 

  1. Copy the script below, or click here to download the BAS file: NamePlots.BAS.
  2. Open your Grapher project, making sure it just contains a single graph with plots from adjacent columns in one data file.
  3. Make sure you have the Script Manager showing. If not, click View | Display | Script Manager to turn it on.
  4. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click the open file icon (​), select the BAS file from your downloads directory, and click Open.
  5. Update the 'datafile' and 'shift' variables on lines 18 and 19.
  6. Click the green arrow (​) to run the script.

'=================================================
'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 August 7, 2017

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.