Use Arcade expressions in charts

Arcade is an expression language written for use in ArcGIS that can perform mathematical calculations, manipulate text, and evaluate logical statements. Arcade expressions are useful for calculating new variables without requiring an update to the dataset's schema. They also have the advantage of being dynamic and data-driven, meaning that an expression result will update if the data that is used in the expression changes.

Arcade can be used to configure bar charts, pie charts, line charts, histograms, and scatter plots. To create or edit an expression for a chart variable that supports Arcade, click the Arcade expression button Arcade expression button to open the expression builder window.

The following examples are potential use cases for configuring charts using Arcade.

Text examples

Arcade provides many functions that process text values to create and configure charts. As an example, make a chart more readable by formatting string values that are all caps (CALIFORNIA) to use title case (California). This can be accomplished using the Proper function in Arcade:

# Format "CALIFORNIA" as "California"

To concatenate multiple string fields into a single text output, use the Concatenate function. The following example combines each feature's city name and state name into a single string:

Concatenate($feature.CITY_NAME, ", ", $feature.STATE_NAME);

Conversely, there may be scenarios in which it would be helpful to parse a string to find specific parts contained within the text. For instance, use the Split function to identify the city name within an address (123 Main Street, Redlands, CA). The following example splits addresses on commas and uses array indexing to identify the city name:

# Split string on "," and return the second element (ie, the city name)
Split($feature.FULL_ADDRESS, ",")[1];

You can also use control structures in Arcade to recategorize text values based on logical conditions. In the following example, the Find function is used to group storm events that are tornado related into a Tornado category, while all non-tornado-related events are grouped into an Other category:

if (Find($feature.EVENT_TYPE, "TORNADO") >= 0) {
    return "Tornado";
} else { 
    return "Other";

Date examples

Arcade provides many functions for processing date-related fields. As an example, a dataset may have multiple fields that provide date information, but these fields must be combined to create a Date field to use in temporal charts. The Date function takes the relevant date components and outputs a date value:

Date($feature.YEAR, $feature.MONTH, $feature.DAY);

To calculate a duration based on two dates, use the DateDiff function. For instance, suppose a service request dataset contains one date field for when the request was opened and another for when it was closed. The following example calculates the number of days that elapsed between the two date values:

DateDiff($feature.OPEN_DATE, $feature.CLOSE_DATE, "DAYS");

Arcade also provides functions for parsing details from a Date field. For example, to understand the day-of-week patterns for a date field, use the ISOWeekday function to return the day of week for a date:


Numeric examples

Arcade provides functions and operators for processing numeric values that can be used to create a chart. As an example, use the AreaGeodetic function to normalize a population by the area of the feature. The following example uses the AreaGeodetic function along with the division operator:

$feature.POPULATION / AreaGeodetic($feature, 'square-miles')

Arcade also provides functions for common mathematical operations. For instance, use the Average function to find the average of multiple values:

Average([$feature.SCORE1, $feature.SCORE2, $feature.SCORE3])

There may also be cases in which it would be useful to categorize numeric data. For instance, for a dataset related to automobile characteristics, convert numeric values for miles per gallon into categories such as Good, Okay, and Poor:

if ($feature.MILES_PER_GALLON >= 30) {
    return "Good"
} else if ($feature.MILES_PER_GALLON >= 20) {
    return "Okay"
} else {
    return "Poor"