HOW TO

Create a pop-up pie chart legend displaying the top values for ArcGIS Pro

Last Published: January 29, 2024

Summary

In ArcGIS Pro, Arcade expressions can be used to display the top field values in a pop-up pie chart legend. This article provides an example and instructions using Arcade expressions to create the pop-up pie chart legend displaying the top three languages spoken at home in Caledon, Ontario, Canada.

Procedure

  1. Start ArcGIS Pro and open the project.
  2. In the Contents pane, right-click the feature class and click Configure Pop-ups to open the Configure Pop-ups pane of the feature class.
Opening the Configure Pop-ups tool of the feature class from the Contents pane
  1. In the Configure Pop-ups pane, click Expressions to add a field using an Arcade expression to use in the pop-up.
  2. In the Expressions pane, click New.
  3. In the Expression Builder dialog box, configure the following parameters for the Arcade expression.
    1. For Name, rename the new expression.
    2. For Title, specify a title for the new expression.
  4. For the Expression section, insert the following Arcade expression.
    1. To define the array parameter storing the competing number field values and the text of the field alias property, specify the following:
var <variableName1> = [
      {value: $feature.<fieldName1>, alias: " <fieldAlias1>"},
      {value: $feature.<fieldName2>, alias: " <fieldAlias2>"},
      ...
      {value: $feature.<fieldName214>, alias: " <fieldAlias214>"}
];
  1. Specify the following statement to re-index the array by array values.
function getValuesArray(a){
  var valuesArray = []
  for(var i in a){
    valuesArray[i] = a[i].value;
  }
  return valuesArray;
}
  1. Specify the following statement to search and compile the field aliases related to the field array.
function findAliases(topA,fullA){
  var aliases = [];
  var found = "";
  for(var i in topA){
    for(var k in fullA){
      if(topA[i] == fullA[k].value && topA[i] > 0 && Find(fullA[k].alias, found) == -1){
        found += fullA[k].alias;
        aliases[Count(aliases)] = {
          alias: fullA[k].alias,
          value: topA[i]
        };
      }
    }
  }
  return aliases;
}
  1. Specify the following statement to sort the array from the highest to the lowest field value, and return the field aliases and field values.
    • For <numberOfTopValuesToDisplay>, input the desired number of top values to display. In this example, the number is 3.
    • For <textToDisplayWhenThereIsNoValue>, input the text to display if the field value is blank. In this example, the text to display is 'Nobody lives here'.
function getTopGroups(groupsArray){
    
  var values = getValuesArray(groupsArray);
  var topValues = IIF(Max(values) > 0, Top(Reverse(Sort(values)),<numberOfTopValuesToDisplay>), "<textToDisplayWhenThereIsNoValue>");
  var topAliases = findAliases(topValues,groupsArray);
    
  if(TypeOf(topValues) == "String"){
    return topValues;
  } else {
    var content = "";
    for(var i in topAliases){
      content += (i+1) + "." + topAliases[i].alias + " - " + Text(topAliases[i].value, "#,###");
      content += IIF(i < Count(topAliases)-1, "<br/>", "");
    }
  }
    
  return content;
}
 
getTopGroups(<variableName1>);
Note:
The legend numbering does not directly represent the ranking when there are more than two similar reference values. For example, the third most spoken languages in the Caledon area are Italian and Tamil, which are spoken in 45 households each.

The code block below shows the full working expression for the top three languages spoken at home in Caledon, Ontario, Canada.

var groups = [
      {value: $feature.MO_Arabic, alias: " Arabic"},
      {value: $feature.MO_Armenian, alias: " Armenian"},
      {value: $feature.MO_Belarusian, alias: " Belarusian"},
      {value: $feature.MO_Bengali, alias: " Bengali"},
      {value: $feature.MO_Bulgarian, alias: " Bulgarian"},
      {value: $feature.MO_Burmese, alias: " Burmese"},
      {value: $feature.MO_Catalan, alias: " Catalan"},
      {value: $feature.MO_Croatian, alias: " Croatian"},
      {value: $feature.MO_Czech, alias: " Czech"},
      {value: $feature.MO_Danish, alias: " Danish"},
      {value: $feature.MO_Dutch, alias: " Dutch"},
      {value: $feature.MO_English, alias: " English"},
      {value: $feature.MO_Finnish, alias: " Finnish"},
      {value: $feature.MO_French, alias: " French"},
      {value: $feature.MO_German, alias: " German"},
      {value: $feature.MO_Greek, alias: " Greek"},
      {value: $feature.MO_Gujarati, alias: " Gujarati"},
      {value: $feature.MO_Hakka, alias: " Hakka"},
      {value: $feature.MO_Hebrew, alias: " Hebrew"},
      {value: $feature.MO_Hindi, alias: " Hindi"},
      {value: $feature.MO_Hungarian, alias: " Hungarian"},
      {value: $feature.MO_Indonesian, alias: " Indonesian"},
      {value: $feature.MO_Iranian_Persian, alias: " IranianPersian"},
      {value: $feature.MO_Irish, alias: " Irish"},
      {value: $feature.MO_Italian, alias: " Italian"},
      {value: $feature.MO_Japanese, alias: " Japanese"},
      {value: $feature.MO_Korean, alias: " Korean"},
      {value: $feature.MO_Latvian, alias: " Latvian"},
      {value: $feature.MO_Macedonian, alias: " Macedonian"},
      {value: $feature.MO_Malay, alias: " Malay"},
      {value: $feature.MO_Mandarin, alias: " Mandarin"},
      {value: $feature.MO_Mongolian, alias: " Mongolian"},
      {value: $feature.MO_Nepali, alias: " Nepali"},
      {value: $feature.MO_Norwegian, alias: " Norwegian"},
      {value: $feature.MO_Polish, alias: " Polish"},
      {value: $feature.MO_Punjabi_Panjabi, alias: " Punjabi(Panjabi)"},
      {value: $feature.MO_Romanian, alias: " Romanian"},
      {value: $feature.MO_Russian, alias: " Russian"},
      {value: $feature.MO_Serbian, alias: " Serbian"},
      {value: $feature.MO_Sindhi, alias: " Sindhi"},
      {value: $feature.MO_Spanish, alias: " Spanish"},
      {value: $feature.MO_Swahili, alias: " Swahili"},
      {value: $feature.MO_Tamil, alias: " Tamil"},
      {value: $feature.MO_Thai, alias: " Thai"},
      {value: $feature.MO_Tibetan, alias: " Tibetan"},
      {value: $feature.MO_Turkish, alias: " Turkish"},
      {value: $feature.MO_Ukrainian, alias: " Ukrainian"},
      {value: $feature.MO_Uzbek, alias: " Uzbek"},
      {value: $feature.MO_Vietnamese, alias: " Vietnamese"},
      {value: $feature.MO_Welsh, alias: " Welsh"},
      {value: $feature.MO_Wu_Shanghainese, alias: " Wu(Shanghainese)"},
      {value: $feature.MO_Yue_Cantonese, alias: " Yue(Cantonese)"}
];

function getValuesArray(a){
  var valuesArray = []
  for(var i in a){
    valuesArray[i] = a[i].value;
  }
  return valuesArray;
}

function findAliases(topA,fullA){
  var aliases = [];
  var found = "";
  for(var i in topA){
    for(var k in fullA){
      if(topA[i] == fullA[k].value && topA[i] > 0 && Find(fullA[k].alias, found) == -1){
        found += fullA[k].alias;
        aliases[Count(aliases)] = {
          alias: fullA[k].alias,
          value: topA[i]
        };
      }
    }
  }
  return aliases;
}
 
function getTopGroups(groupsArray){
    
  var values = getValuesArray(groupsArray);
  var topValues = IIF(Max(values) > 0, Top(Reverse(Sort(values)),3), "Nobody lives here");
  var topAliases = findAliases(topValues,groupsArray);
    
  if(TypeOf(topValues) == "String"){
    return topValues;
  } else {
    var content = "";
    for(var i in topAliases){
      content += (i+1) + "." + topAliases[i].alias + " - " + Text(topAliases[i].value, "#,###");
      content += IIF(i < Count(topAliases)-1, "<br/>", "");
    }
  }
    
  return content;
}
 
getTopGroups(groups);
  1. Click Verify to run a test of the expression. If the expression is valid, click OK.
The Expression Builder dialog box with an example of the Arcade expression
  1. In the Expressions pane, click Back The Back icon.
The Expressions pane
  1. Click Text to add the text pop-up element and click Edit pop-up element Edit Pop-up Element on the Text element.
The Configure Pop-ups pane
  1. In the Text Options pane, specify a title for the legend and the newly created expression. In this example, the newly created expression is {expression/expression3}. Click Back The Back icon to apply the text pop-up element configuration.
The Text Options pane

The image below shows the newly configured pop-up pie chart legend with the top three most spoken languages in Caledon, Ontario, Canada.

The newly configured pop-up pie chart legend in ArcGIS Pro

Article ID: 000031637

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 3 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