Follow

How do I change the properties of my legend entries in a Grapher script?

This article contains a sample script showing how to create a graph with multiple plots, add a legend, and change all of the legend entries to have similar properties.

 

To run this script:

  1. Copy the script below, or click here to download the BAS file: change all legend entries.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
	'Declare the variable that will reference 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

	'Creates a new plot window and assign it to the variable named "Plot"
	Set Plot1 = GrapherApp.Documents.Add(grfPlotDoc)

	'Add LinePlotGraph
	Set Graph1 = Plot1.Shapes.AddLinePlotGraph(GrapherApp.Path + "\samples\tutorial.dat")

	'Add additional line/scatter plots
	Graph1.AddLinePlot(GrapherApp.Path + "\samples\tutorial.dat",,3)
	Graph1.AddLinePlot(GrapherApp.Path + "\samples\tutorial.dat",,4)
	Graph1.AddLinePlot(GrapherApp.Path + "\samples\tutorial.dat",,5)
	Graph1.AddLinePlot(GrapherApp.Path + "\samples\tutorial.dat",,6)
	Graph1.AddLinePlot(GrapherApp.Path + "\samples\tutorial.dat",,7)
	Graph1.AddLinePlot(GrapherApp.Path + "\samples\tutorial.dat",,8)
	Graph1.AddLinePlot(GrapherApp.Path + "\samples\tutorial.dat",,9)

	'Change the colors of each line
	Graph1.Plots.Item(1).line.foreColor = grfColorBlue
	Graph1.Plots.Item(2).line.foreColor = grfColorGreen
	Graph1.Plots.Item(3).line.foreColor = grfColorRed
	Graph1.Plots.Item(4).line.foreColor = grfColorMagenta
	Graph1.Plots.Item(5).line.foreColor = grfColorPurple
	Graph1.Plots.Item(6).line.foreColor = grfColorOrange
	Graph1.Plots.Item(7).line.foreColor = grfColorPastelBlue
	Graph1.Plots.Item(8).line.foreColor = grfColorOceanGreen

	'Add legend
	Set Legend = Graph1.AddLegend(True)

	'Link each entry to specific worksheet cell
	Legend.EntryName(1,"<<@b1>>")
	Legend.EntryName(2,"<<@c1>>")
	Legend.EntryName(3,"<<@d1>>")
	Legend.EntryName(4,"<<@e1>>")
	Legend.EntryName(5,"<<@f1>>")
	Legend.EntryName(6,"<<@g1>>")
	Legend.EntryName(7,"<<@h1>>")
	Legend.EntryName(8,"<<@i1>>")

	'Link legend entries to worksheet
	i=1
	While i < Legend.EntryCount+1
		Legend.EntryFont(i).worksheet = GrapherApp.Path+"\Samples\Tutorial.dat"
		i=i+1
	Wend

	'Change entry font for all lines
	i=1
	While i <= Legend.EntryCount
		Legend.EntryFont(i).face = "Times New Roman"
		Legend.EntryFont(i).Bold = True
		Legend.EntryFont(i).color = grfColorGreen
		Legend.EntryFont(i).Italic = True
		Legend.EntryFont(i).size = 8
		i=i+1
	Wend

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.