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:
- Click here to download the BAS file: NamePlots.BAS.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Click the Open (
) icon in the Script Manager, select the downloaded BAS file, and click Open.
- Click File | Open, select your Grapher project, and click Open.
- On Line 18 of the script, edit the datafile path to define the worksheet used to create your plots.
- 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.
- Click the Start/Resume (
) icon in the Script Manager.
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 File | Open, select your Grapher project, and click Open.
- On Line 18 of the script, edit the datafile path to define the worksheet used to create your plots.
- 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.
- 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
Comments
Please sign in to leave a comment.