Arcade Symbology

2075
29
Jump to solution
06-27-2019 08:48 AM
Highlighted
New Contributor II

I am trying to display pavement condition inventory scores as groups, for instance 60-75 is okay, 76-89 is good, and 90-99 is excellent. I can do that in Map, but not Online. There is no grouping setting I can find. You can use Counts and Amounts and set the manual breaks, but you can't change individual colors in the ramp. I am not good with Arcade, but I found something that partially works. The problem is it only returns 3 categories. That may be all it is designed to do. Does anyone have any suggestions? Thanks!

if($feature.PCI >=90){

    return "Great"

}

if (75<= $feature.PCI <90){

    return "Better"

}

if (60<= $feature.PCI <75){

    return "Okay"

}

if(40<= $feature.PCI <60){

    return "Bad"

}

if($feature.PCI <40){

    return "Awful"

}

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Esteemed Contributor

Hi dpyron_hv 

It is better to use if - else if - else statements. Can you try this:

var PCI = $feature.PCI;

if (PCI < 40) {
return "Awful";
} else if (PCI < 60) {
return "Bad";
} else if (PCI < 75) {
return "Okay";
} else if (PCI < 90) {
return "Better";
} else {
return "Great";
}

If your data does not have values in each class, those classes will not be returned by the expression.

View solution in original post

Reply
0 Kudos
29 Replies
Highlighted
Esri Esteemed Contributor

Hi dpyron_hv 

It is better to use if - else if - else statements. Can you try this:

var PCI = $feature.PCI;

if (PCI < 40) {
return "Awful";
} else if (PCI < 60) {
return "Bad";
} else if (PCI < 75) {
return "Okay";
} else if (PCI < 90) {
return "Better";
} else {
return "Great";
}

If your data does not have values in each class, those classes will not be returned by the expression.

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor II

Thank you Xander, that worked perfectly! I really need to take class in this.

Highlighted
Esri Esteemed Contributor

Hi Darla Pyron 

There is really a lot you can do with Arcade expressions and there are a lot of resources available as blog posts: 

https://www.esri.com/en-us/search#/?q=Arcade&v=0&tab=Explore&page=1

The official documentation site of Arcade contains a list of all expressions you can use: https://developers.arcgis.com/arcade/function-reference/ and I use the playground a lot to test an expression when I don't have access to the data: https://developers.arcgis.com/arcade/playground/

Also here at GeoNet there are a lot of documents with explanations of different use cases. Just search for Arcade and filter on document or blog post:

https://community.esri.com/search.jspa?q=Arcade&type=post

https://community.esri.com/search.jspa?q=Arcade&type=document

And whenever you have a question, just post it here on GeoNet and tag me. We are here to help.

Reply
0 Kudos
Highlighted
New Contributor II

Thank you Xander, that worked perfectly!

Reply
0 Kudos
Highlighted
New Contributor II

Thank you Xander, that shows exactly what I needed.

Darla

Get Outlook for Android<https://aka.ms/ghei36>

Reply
0 Kudos
Highlighted
New Contributor II

Xander I was looking to do something similar to this but it seems as if the IF statement is only catching the first argument in the if statement and ignoring my &&

var Printed = $feature.Printed
var Worked = $feature.Worked
var Entered = $feature.Entered

if (Printed == 'YES' && Worked == 'NO' && Entered == 'NO') {
return "Printed";
} else if (Printed == 'YES' && Worked == 'YES' && Entered == 'NO') {
return "Worked";
} else if (Printed == 'YES' && Worked == 'YES' && Entered == 'YES') {
return "Entered";
} else {
return "Needs Printing";
}

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

Hi dansalazar ,

Can you try this?

var Printed = $feature.Printed;
var Worked = $feature.Worked;
var Entered = $feature.Entered;

if (Printed == 'YES') {
if (Worked == 'NO') {
if (Entered == 'NO') {
// YES NO NO
return "Printed";
}
} else {
if (Entered == 'YES') {
// YES YES YES
return "Entered";
} else {
// YES YES NO
return "Worked";
}
}
} else {
return "Needs Printing";
}

Not sure as to why it would ignore the &&. I have to run some test to find out.

Reply
0 Kudos
Highlighted
New Contributor II

Hi Xander, I tried something similar to Daniel.

I have 3 fields which either contain a number value or don't.

I tried the following code to no avail:

----------

var a = $feature["Ronde1_wk"];

var b = $feature["Ronde2_wk"];

var c = $feature["Ronde3_wk"];

var x = iif( !isEmpty( a ), 1, 0);

var x = iif( !isEmpty( b ), 2, 0);

var x = iif( !isEmpty( c ), 3, 0);

var list = [x,y,z];

return Max( list )

----------

When testing in the arcade module it returns either 0,1,2 or 3 like you would expect.

When I am to apply set expression the module only returns 0 and 1.

I tried applying your aforementioned cascaded if statement but i had no succes.

I had no succes with DefaultValue instead of isEmpty either (making the if statement (a > 0))

Is there somehting I'm missing?

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

Hi Martijn Jansma ,

I am a bit curious to know what kind of data you are storing in the fields (and what world championship it refers to ). The logic should work although in the expression you shared assigns 3 times a value to variable x (when it should be x, y and z). I am sure that you have that in your original code, since otherwise the code would not run at all.

It would be interesting to validate the data the gets retrieved and processed. Could you try the code below and report back what is written to the console?

var a = $feature["Ronde1_wk"];
var b = $feature["Ronde2_wk"];
var c = $feature["Ronde3_wk"];
var data = [a, b, c];
Console(data);

var x = iif(!isEmpty(a), 1, 0);
var y = iif(!isEmpty(b), 2, 0);
var z = iif(!isEmpty(c), 3, 0);
var list = [x,y,z];
Console(list);

return Max(list);
Reply
0 Kudos