Execute Arcade for a custom chart
This sample demonstrates how to execute an Arcade expression outside the rendering context of a web map layer to create a scatter plot chart. Arcade expressions are executed in the context of a profile, which defines where an expression executes, which variables it can use, and what data types it can return. For example, the visualization Arcade profile is defined by the following rules:
- Execution context: Expressions may only execute in the
value
property of a renderer, visual variable, or CIMSymbol primitive override.Expression - Profile variables:
$feature
- The feature for which to calculate a value. Expressions have access to its geometry and attributes.$view.scale
- The view scale, for scale-dependent visualizations.
- Valid return types:
number
ortext
, depending on the context.
This example loads a web map that defines a renderer based on an Arcade expression that calculates the diversity of languages spoken in the home. The layer provides the total population that speak a language in each of five different language groups in the United States. The following is an expression referenced by a color visual variable, which colors each symbol along a continuous color ramp based on each feature's result of the expression.
This expression isn't present in the sample app, but it is stored in the web map.
This expression executes for each feature within the rendering engine, and the values are not available to the developer or end user for any other purpose. However, you can use the createArcadeExecutor method in the esri/arcade module to execute expressions stored in web maps (or used in any other part of your application) outside its original context for some other purpose. This sample shows how to do this for creating a chart based on the results of the expression above.
First, get the Arcade expression from the color variable in the layer's renderer.
Then, define the profile used to execute the expression. This specifies the variables used and their associated Arcade types. You can either create the profile object yourself from the Arcade profile specs...
Or use the convenient createArcadeProfile method.
Then create the executor, which compiles the expression for the given profile.
Once successfully compiled, execute the expression for each feature in the layer view. Once you have the results, you can build a chart or display the values in a table or some other component.
Related samples and resources

Reference Arcade expressions in PopupTemplate
Reference Arcade expressions in PopupTemplate

Summarize intersecting points in a popup
Summarize intersecting points in a popup

Update a renderer's attribute
Update a renderer's attribute's attribute

Create a custom visualization using Arcade
Create a custom visualization using Arcade
API Reference
Read the API Reference for more information.