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
Thanks
John Esch
Solved! Go to Solution.
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.
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.
Thanks for your help