Select to view content in your preferred language

Looking for an Arcade expression that will query Census tract language spoken fields (40 fields) and return the highest 6 languages and their %s

765
2
Jump to solution
02-09-2023 04:02 PM
Labels (1)
JohnEsch1
Occasional Contributor

The goal is to take to the results of the above expression and use populate a pie chart using ArcGIS Online Map Viewer Classic, Popup, Arcade Expression and pie chart. So if one clicks on any Census tract, they would see standard pop up attributes and pie chart showing the higher 6 spoken languages. 

See example of the Census tract data with 9 of the 40 languages

JohnEsch1_0-1675987114039.png

Thanks

John Esch

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Popup pie charts will need an expression for each slice, but you can re-use the following expression:

# array of language fields
var lang_arr = [
    $feature.language1,
    $feature.language2,
    ...
    $feature.language40
]

# sort the array largest to smallest
var lang_sorted = Reverse(Sort(lang_arr))

# grab the top item
return lang_sorted[0]

 Sort will, by default, sort in ascending order. You could write a custom sort function, but it's simpler to just wrap it in Reverse.

When using this expression for successive items, just change the number in the last line. Arrays are 0-indexed, so returning lang_sorted[1] would be the second-highest number, lang_sorted[2] third-highest, and so on.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

Popup pie charts will need an expression for each slice, but you can re-use the following expression:

# array of language fields
var lang_arr = [
    $feature.language1,
    $feature.language2,
    ...
    $feature.language40
]

# sort the array largest to smallest
var lang_sorted = Reverse(Sort(lang_arr))

# grab the top item
return lang_sorted[0]

 Sort will, by default, sort in ascending order. You could write a custom sort function, but it's simpler to just wrap it in Reverse.

When using this expression for successive items, just change the number in the last line. Arrays are 0-indexed, so returning lang_sorted[1] would be the second-highest number, lang_sorted[2] third-highest, and so on.

- Josh Carlson
Kendall County GIS
JohnEsch1
Occasional Contributor

Thanks for your help

0 Kudos