Building label expressions

You can use label expressions to adjust the formatting of your labels. In addition to inserting characters and scripting functions, you can use ArcGIS formatting tags in label expressions. These are special characters for changing the appearance of all or part of your labels. For example, you might use the bold formatting tag to make the first line bold in a stacked, multiline label.

Learn more about formatting labels with text formatting tags

A label expression is limited to a single line of code unless you check the Advanced box on the Label Expression dialog box. Checking the Advanced box allows you to enter a function containing programming logic and spanning multiple lines of code.

Field values are automatically cast to text strings. Therefore, if you wish to use a numeric value in an arithmetic operation, or when making a comparison, you will need to cast it back to a numeric data type. The examples below add two integer fields:

Python
int([FIELD1]) + int([FIELD2])
VBScript
cint([FIELD1]) + cint([FIELD2])
JScript
parseInt([FIELD1]) + parseInt([FIELD2])

Steps:

  1. Click the Label Manager button Label Manager on the Labeling toolbar.
  2. Click a label class in the Label Classes list.
  3. Click the Expression button.
  4. Choose a language on the Parser menu.
  5. Type a Python, VBScript, or JScript expression. You can also create an expression by double-clicking the field to add it to the expression or by selecting the field and clicking the Append button to append the field to the end of the expression separated by a space.

    Fields are enclosed in square brackets [ ] irrespective of the data type of the layer's data source.

    Optionally, enter ArcGIS text formatting tags in the Expression box to apply formatting to a portion of your label text.

    If your expression will span multiple lines of code, check the Advanced check box and enter your label expression.

  6. Click Verify to make sure there are no syntax errors.
  7. Click OK on each of the dialog boxes.
TipTip:
Both regular and advanced label expressions can be saved as label expression files (.lxp), which can be loaded into other layers or maps.

Expression examples

The following are examples of label expressions:

NoteNote:
To label a subset of features based on a field value, create the SQL query in the label class instead of through the label expression.

(This information is housed on web pages not created, owned, nor maintained by Esri. Esri cannot guarantee the availability of these pages and is not responsible for the content found on them.)

Related Topics

10/24/2012