# 8.10.1.3 Linking Text Labels to Data and Variables

Origin supports various types of hyperlinks in text labels. The syntax for links is as follows:

range://: indicates a range inside the project.
http:// or https://: indicates an external link.
help://: indicates a link to the Origin help documentation.
note://: indicates a link to a Notes window.

In each case, the link is put into the text box in the object Properties Programming tab (Alt+double click on the text label) while the displayed text is put into the text box on the Text tab (Double-click). The text label will be underlined indicating that it is a hyperlink.

A text label can also be made into a button that performs some action when clicked. See Examples 3 and 4 for instructions.

1. Enter the following in a graph's text label:
Go to column 1, row 100
2. Right-click on the text label and select Properties... from the context menu and go to Programming tab in the dialog.
3. Enter the following in the script box at the bottom of the dialog and click OK.
range://[book1]sheet1!col(1)[100]
4. Click on the text label to open Book1, Sheet1 and have it scroll to the cell in column 1, row 100.

Note: the link will do nothing if the destination range doesn't exist.

1. Enter the following in a graph's text label:
originlab.com
2. Right-click on the text label and select Properties... from the context menu and go to Programming tab in the dialog.
3. Enter the following in the script box and click OK.
http://www.originlab.com
4. Click on the label to open a browser to the OriginLab's home page.

### Example 3. Linked Help file page button

1. Enter the following in a graph's text label:
Click to see the Spacing tab help file
2. Right-click on the text label and select Properties... from the context menu and go to Programming tab in the dialog.
3. Enter the following in the script box, making sure to enclose the link in double-quotes:
run -LK "help://origin.chm/UserGuide/The_(Plot_Details)_Spacing_Tab.html"
4. Set Script,Run After to Button Up, and click OK.
5. Press the button to open the Origin CHM to "The (Plot Details) Spacing tab" page.

### Example 4. Linked Notes window button

1. Creat a new Notes window Notes1
2. Enter the following in a graph's text label:
Go to Notes1
3. Right-click on the text label and select Properties... from the context menu and go to Programming tab in the dialog.
4. Enter the following in the script box, making sure to enclose the link in double-quotes:
run -LK "notes://Notes1"
5. Set Script,Run After to Button Up, and click OK.
6. Press the button to go to the Notes1 window.

Note: the button will do nothing if the specified Notes window doesn't exist.

## Substituting Values for Data and Variables in Text Labels

Text labels can as simple as a static object or they can be dynamic objects that resolve by linking to a wide variety of project information including worksheet cell values, data file names, worksheet column metadata, or dataset statistics.

Whether considering (1) auto-generated objects such as axis titles, legends or data point labels or (2) user objects added with the Text or Annotation tools, we are generally relying on LabTalk Substitution Notation to insert specific text strings and numeric quantities into our text labels in real-time.

Within the context of the graph window, text labels can be lumped into two groups:

• Graph text labels: These include axis titles and graph legends, as well as labels added with the Text tool . See this page for information on user-added labels. See these pages for information on Graph Legends or Axis Titles.
• Data Plot Labels: These are labels applied to data points (single points or entire datasets) either using the Annotation tool or by enabling labels using Plot Details Label tab controls. See Labeling Data Points for information.

### Substituting worksheet cell values in text labels

There are several ways to display worksheet cell data in the text labels. The simplest (though also the most limited) is to simply Paste-Link the contents of a worksheet cell. More involved methods incorporate LabTalk Substitution.

#### Example 1. Insert cell value by Paste-Link

This is the simplest way to combine a worksheet cell value and some literal text:

1. Click on a worksheet cell and press CTRL+C (or right-click and Copy).
2. Use the Text tool to create your literal text (e.g. The value of y is:), then while still in label edit mode, right-click and choose Paste Link. This inserts the cell value into the text object. Note that since you are paste-linking, a change to the worksheet cell value will trigger a change to the value shown in your label.

You can use this method to insert values from either the data or the column label row portions of your worksheet. More sophisticated methods for inserting cell values -- specifically, those that use substitution notation -- can be more flexible. However, if all you need is to return a value from a specific worksheet cell, this may suffice.

#### Example 2. Insert cell Value using substitution notation

This example introduces basic substitution to return cell contents, using the form %(workbookName, column#, row#).

1. To insert the cell value in Book1, column 2, row 5, type the following into a text label:
The value of y is %(Book1,2,5)
2. Right-click on the text label and choose Properties. On the Programming tab, set Link to (%,$), Substitution Level to 1 and click OK.  Notes: Examples 1 and 2 have a limitation in that the source worksheet name cannot be changed, otherwise the link between worksheet and label is broken. In the next example, we show how to handle this. #### Example 3. Insert cell value using @WT to refer to plot source Most data plots in Origin are created from a single column of data. All data in that column, including metadata in column label rows, is thus associated with that data plot. Building your substitution string using text label option @WT allows you to return a worksheet cell value by referencing the source data for the plot. Unlike Example 2, you avoid the limitation of having to reference a fixed book or sheet name. Let's say, for example, that you want to create a text label that reads "The value of y is number," where number is the value read from cell at 2nd column and 5th row in the source worksheet of plot 1. 1. Type the following text in WYSIWYG edit mode or enter in the Object Properties dialog box and click OK. The value of y is %(1, @WT,2,5) 2. Right-click on your text label and select Properties... and go to Programming tab in the dialog. Or press the ALT key while double-clicking on the text label. 3. Set Link to (%,$), Substitution Level to 1 and click OK.

The advantage of this method is that the worksheet column that @WT refers is identified by plot source. When you save the graph as a Graph Template and reuse it later, the display content of the text label will automatically update according to the new data, even if dataset name is changed.

 Notes: Alternately, you can refer to a column by name -- either Short or Long Name -- using %(1, @WT,ColName,RowIndex). The %(1, @WT,ColIndex,RowIndex) notation can be used to reference a matrixsheet value.

#### Example 4. Insert cell value and modify numeric format

Some syntaxes support formatting of returned numeric values using these numeric formatting options. For instance, if you follow the method of Example 2, above, you will be returning a full-precision value from the sheet. To control the number of displayed digits returned, you could an optional format specifier to your expression. Here, there are multiple syntaxes that will work:

• $(expression [,format]) • %([workbookname]sheetname, column, row [,format]) • %([workbookName]sheetName, @WL, column[row] [,format]) the last syntax -- the @WL example -- supports these handy format options: Argument Description W Return in the cell format. custom format Return the full precision value of the cell, modified by one of these Origin Formats. omitted Return the full precision value of the cell. So, for example, to return the value in Book1, column 2, row 5 and format it to four decimal digits, you could use one of the following: •$(%(Book1,2,5),.4)
•  %([Book1]Sheet1,B,5,.4)
•  %([Book1]Sheet1,@WL,2[5],.4)

### Substituting column label row values (metadata) in text labels

In addition to data row cells, you can substitute values from column label row cells in your text labels. There are several syntaxes that will work, depending upon your needs.

For the next couple of examples, refer to the figure above.

#### Example 1: User-created text label

For user-created labels of data plotted in the graph, use this syntax:

%(PlotDesig, @option)

... where PlotDesig = 1X, 1Y, 2Y, etc. and the @option is one of those listed in this table.

Examples:

%(1X,@LU) --> (sec)
%(1Y,@LU) --> (K)
%(2Y,@LU) --> (Oe)

#### Example 2: Plot Details Label tab Format String

When labeling a plot using the Plot Details Label tab controls, use

%(wcol(n)[LabRowChar]$) ... where wcol(n) is entered literally and LabRowChar is one of the Column Label Row Characters in this table. Examples: %(wcol(n)[L]$) --> Delta Temperature (1st plot)
%(wcol(n)[L]$) --> Magnetic Field (2nd plot) %(wcol(n)[L]$) --> Position (3rd plot)

Note that in this example, we are using a single notation to show a label only at the last data point.

### Substituting variable values in text labels

Besides displaying worksheet values, you can include variable values in text labels. The basic procedure is to create a text label that uses LabTalk Substitution Notation, then enable variable substitution in the text label's Programming tab of the Object Properties dialog. The variable value will be substituted into the text label. You can insert both string and numeric variable values in this way.

#### Example 1. String substitution

The first example inserts a string variable into a text label. When Origin runs, there are a number of reserved string variables that are used to store system data. Please refer to this page for a detailed list of Substitution Notations.

Assume that your current project MYPROJECT.OPJ is saved to C:\MYFILES\.

1. Using WYSIWYG text labeling methods, type the following into a text label in a graph window:
This project is saved to %X%G.OPJ.
2. Exit the typing mode, right-click to select the label and choose Properties and go to Programming tab in the dialog.
4. Right-click on the text label, choose Properties and go to Programming tab in the dialog, set the Link to (%,$), Substitution Level list to 1, then click OK. Your text label should now display the numeric value of MyVariable. MyVariable=5  To see a list of available LabTalk variables, open the Script Window (Window: Script Window) and click Tools: Variables... or type "ed" at the command line. ### Resolving math expressions in text labels We've seen that Origin supports substitution notation when creating text labels using the standard WYSIWYG text editing methods or when editing text in the Object Properties dialog box. You can also use this notation to resolve a mathematical expression to a value in the text label:$(expression)

In this substitution notation, expression is resolved to a value each time the text label is redrawn. The text label is redrawn whenever you move the label or redraw the graph window.

#### Example. Resolving pi in a text label

1. Type the following text in WYSIWYG edit mode or enter the expression in Text tab of the Object Properties dialog box and click OK.
The value of X is $(pi^2) 2. Right-click on your text label, select Properties... and go to Programming tab. Or, press the ALT key while double-clicking on the text label. 3. Set Link to (%,$), Substitution Level to 1 and click OK. The label now reads:
The value of X is 9.8696

You may need to click the Refresh button on the Standard toolbar to see the change.

 When Origin starts, a text file in the program folder named ORGSYS.CNF is read. It is in this file that the value of pi is defined, in exactly the same way as you would define a constant or a variable at in the Script Window or the Set Column Values dialog box: const pi = 3.141592653589793 If you have mathematical constants that you regularly use in your work, the ORGSYS.CNF file is a good place to define them, as they will always be available when Origin runs (the .CNF file is a text file that you can edit in a simple text editor).