8.12.1.3 Linking Text Labels to Data and Variables


Text labels can incorporate Origin worksheet cell values and variable values by inserting LabTalk Substitution Notation and Text Label Options into the labels. They are both supported by WYSIWYG and Text tab in the Object Properties dialog box text label creation and editing methods. Text labels can also hyperlink to internal and external windows, as well as to the Origin help files.

Displaying worksheet data in text labels

There are several ways to display worksheet cell data in the text labels.

Example 1. Substitution notation combined with @WT

Substitution Notation, combined with Text Label Options @WT, allows you to link text label to a worksheet cell (including column label rows) and display cell value.

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 dailog. 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 @WT refers to is based on plot. 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 though the dataset name is changed.

Note: The %(1, @WT,ColIndex,RowIndex) notation can be used to reference a matrix sheet value. For more information, see Complete List of @Options

Example 2. Pasting cell value as link

Continue to use the story in Example 1. In this example, we will simply use a shortcut menu command to accomplish the same thing. Assume the source worksheet of plot 1 is the first Worksheet in Book1.

  1. Go to [Book1]Sheet1!, select cell in column 2, row 5 and copy the cell contents, using CTRL+C or by right-clicking and choosing Copy.
  2. Use the WYSIWYG way to create a label with the following text:
    The value of y is
  3. While still in in-place edit mode, right-click and choose Paste Link. This inserts the cell value into the text object. Note that this is a "linked" object. If the worksheet cell value changes, so will the value displayed in the text object.

Example 3. Substitution notation only

Continue to use the story in Example 1. This time, we use a more-complicated method. That is, creating a text label that incorporates substitution notation only.

  1. This method requires you to create your expression using LabTalk substitution notation:
    %(Book#,Col#,Row#)
    So, to insert the value of cell at row 5, column 2 of the Book1 worksheet, type the following into a text label:
    The value of y is %(Book1,2,5)
  2. Then set Link to (%,$), Substitution Level to 1 in the object's Programming tab of the Object Properties dialog (you might have to refresh the window to display properly).
Notes: Methods mentioned in Example 2 and 3 have a limitation that the source worksheet name cannot be changed, otherwise the link between worksheet and label is broken.

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.
  3. Set the Link to (%,$), Substitution Level list to 1, and click OK.
  4. Right-click on the text object, choose Properties and select the Verbatim check box (this causes the "\" character to be handled as a literal character instead of an escape character -- see below). The label should display the drive path and name of the current project.
    This project is saved to C:\MYFILES\MYPROJECT.OPJ.

For information on use of the Verbatim option see Use of the backslash "\" character in the Object Properties dialog box.

Example 2. Numeric Substitution

Using LabTalk, you can define any number of variables for use in your work. As an introduction to the concepts of "variables" and "scope", we recommend that you read this topic. To illustrate basic numeric substitution, we give the following simple example:

  1. On the main menu, click Window: Script Window.
  2. Click inside the Script Window and at the cursor, type:
    MyVariable=5

    and press Enter.
  3. From the Tools toolbar, select the Text Tool, click in an empty space on a graph or worksheet window and enter the following:
    MyVariable=$(MyVariable)
  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 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 Porperties... 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 Button Refresh.png 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).

Link to open a Range, External link, or Help documentation

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 in the Programming tab (Alt+double click) and display text put in the Text tab (Double click) in the Object Properties dialog . The display text will appear with an underline indicating it is a link.

A text label can also be turned into a button which will open the link by using the run -LK labtalk command and selecting Button Up for Script, Run After in the Programming tab of Object Porperties dialog. In these cases, the linking text must be enclosed in quotes. (See examples 3 and 4)

Example 1. Range link

  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 Porperties... 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.

Example 2. External link

  1. Enter the following in a graph's text label:
    originlab.com
  2. Right click on the text label and select Porperties... 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 Porperties... from the context menu and go to Programming tab in the dialog.
  3. Enter the following in the script box:
    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 Porperties... from the context menu and go to Programming tab in the dialog.
  4. Enter the following in the script box:
    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.

Refer to this page to see more examples.