HOW TO

Create fractions as labels using Arcade in Portal for ArcGIS and ArcGIS Online Map Viewer

Last Published: June 7, 2024

Summary

In Portal for ArcGIS or ArcGIS Online Map Viewer, labelling a feature class with fractions can be an efficient method to represent statistical analysis. It also provides comparisons between different areas or data points, for example, comparisons of the fraction of renewable energy use across regions.

This article describes the workflow to create the fractions as labels using ArcGIS Arcade in Portal for ArcGIS and ArcGIS Online Map Viewer.

Procedure

  1. In Portal for ArcGIS or ArcGIS Online Map Viewer, open the web map containing the features.
  2. On the Contents (dark) toolbar, click Layers to open the Layers pane and select the layer to be configured.
  3. On the Settings (light) toolbar, click More > Labels.
  4. In the Label features pane, toggle Enable labels on.
  5. Click Add label class and under Label field, click Use expression The Use expression button.
  6. In the editor window, create a name for the Arcade expression and specify the Arcade expression.
    1. Obtain the field value numerator and denominator. Replace <fieldName1> and <fieldName2> with the names of the desired fields.
var fieldA = $feature["<fieldName1>"];
var fieldB = $feature["<fieldName2>"];
  1. Check if the denominator is not zero to avoid division by zero.
if (fieldB == 0) {
  return "undefined";
}
  1. Format the fraction as a string.
var fraction = Text(fieldA, "#") + " / " + Text(fieldB, "#");
  1. Return the formatted fraction.
return fraction;

The code below demonstrates the full working script.

var fieldA = $feature["Numbers"];
var fieldB = $feature["TestNumber"];

if (fieldB == 0) {
    return "undefined"; // or return some default value or message
}

var fraction = Text(fieldA, "#") + " / " + Text(fieldB, "#");

return fraction;
  1. Click Done.

The map shows the fractions displayed as labels in Portal for ArcGIS and ArcGIS Online Map Viewer.

The fractions are displayed as labels

Article ID: 000032736

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options