Custom order values in Serial Chart using Arcade.

03-22-2023 01:20 PM
New Contributor


I'm writing a Arcade expression to input data in a serial chart in Dashboards.

The goal is to replace the string values to numbers so I can order the bars and keep the string as the label.

This function retrieves the feature set using FeatureSetByPortalItem, gets the first feature using First, and assigns the value of the 'ultima_consulta_medica' field to the variable ultima_consulta_medica.

The Replace function is then called on ultima_consulta_medica, replacing the string 'Menos de 1 mês' with the number 1. 


var featureSet = FeatureSetByPortalItem(Portal('myPortal'), 'xxxxx' , 1, ['ultima_consulta_medica'], false);
var feature = First(featureSet);
var ultima_consulta_medica = feature['ultima_consulta_medica'];
ultima_consulta_medica = Replace(ultima_consulta_medica, 'Menos de 1 mês', '1');

return ultima_consulta_medica;


I was stuck trying to make the expression loop through all the values of the ultima_consulta_medica. I need the end result to replace the string with '1'. 

I also don't know if my approach was the best way to resolve my problem.

Any suggestions?

0 Kudos
1 Reply
MVP Esteemed Contributor

In order to loop through your features, you literally need to use a for loop. In Data Expressions, that usually means creating a dictionary and pushing features into it, one by one.

var fs = FeatureSetByPortalItem(...)

var out_dict = {
    fields: [{name: 'ultima_consulta_medica', type: 'esriFieldTypeString'}],
    geometryType: '',
    features: []

for (var f in fs) {
    var new_str = Replace(
        'Menos de 1 mês',
        {attributes: {ultima_consulta_medica: new_str}

return FeatureSet(Text(out_dict))


There are more efficient ways to do this sort of thing, though, if the data permits it. Does the string "Menos de 1 mes" appear in a consistent position?

- Josh Carlson
Kendall County GIS
0 Kudos