Color: Green for type A, scale of yellow - red for type B, white for type C

2167
7
Jump to solution
06-10-2020 03:36 PM
AndyH
by
New Contributor II

I currently am using two layers to display outages vs non-outages, however I really need them to be a single layer so that dashboard / app components can count them together. Outages are currently yellow - red based on duration (older they get the redder they get), and non-outages are always green. This looks perfect on the map, but I can't figure out how to do this in a single layer to make what I want to happen on the dashboard / apps.

My initial thought was to use an arcade expression to return the color ie RGB(123,0,0) for an outage and RGB(0,255,0) for a non-outage. However, I can't seem to be able to define the color AS an expression, I can only determine the color BASED ON an expression value. 

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Andy H ,

I think I found what you are looking for. Let's say that we have a featurelayer with 3 types of outages (see values A, B and C in field Outage Type) and the data when the outage was reported (field Outage Date):

When the Outage Type is "B" the color should vary from yellow to orange to red, where red indicate that most time has passed. Like this:

To get there you will nee to do the following. First define the symbology based on the outage type and assign the green and white colors to A and C. Then you will have to go into the second tap "vary the symbology by attribute":

To be able to create the colors for outage type "B", you will have enable the option "Allow symbol property connections":

When you do this, you can now create the color effect for outage type B based on the date. Click on the symbol for outage type B:

You will now be able to enter the properties, and activate the layers and to the right hand side you will see a grey icon that will allow you to define how to vary in this case the color. In my case the symbol is already blue since I already defined the attribute mapping:

This will open an interface where you can select an existing field or you can define an Arcade expression. I use the Arcade expression to define the scale of colors:

Since the colors should vary from yellow (most recent outages) to red (most dated outages) you can use the DateDiff function to calculate the difference between the current date and the date stored in the Outage Date field. Since to go from yellow, through orange to red you just vary the green intensity from 255 to 0, you can use a simple calculation. In my case my maximum time was 11 days so I divide the calculated days by 11 invert the result  and multiply by 255. Then I construct the text to return "rgb(255, green, 0)" and that is all. If your green value will be out of the range from 0 to 255, it will be limited to 0 - 255. 

Example Arcade expression:

var days = Abs(DateDiff(Now(), $feature.OutageDate, "days"));
var green = Round((1.0 - (days / 11.0)) * 255,0);
return "rgb(255," + green + ",0)";

Let me know if you run into any problems.

View solution in original post

7 Replies
XanderBakker
Esri Esteemed Contributor

Hi Andy H ,

Although you mention that you want to create a color based on the attributes; outages vs non-outages and time of the outage, you can also create an expression that returns a classified value (non-outage, outage time range 1, outage time range 2, etc) and assign the symbology accordingly. Would that be something you are after or do you have to manipulate the color directly by Arcade?

AndyH
by
New Contributor II

First thank you for taking the time to respond!!

 

It doesn’t have to be by arcade, but I really like the color scale being gradual, so I’d prefer not to have it in 'bins'. The other problem is that I don’t want the colors to be green, red, blue, yellow (ie random) nor do I want all of them to be shades of red etc, they've got to be individually distinct.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi soldstatic ,

It sounds a lot like you are trying to use Attribute-driven color in symbology—ArcGIS Pro | Documentation . I have seen that there were some problems in the past, but I have the idea that this should be working now. Let me test something out and I will get back to you. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Andy H ,

I think I found what you are looking for. Let's say that we have a featurelayer with 3 types of outages (see values A, B and C in field Outage Type) and the data when the outage was reported (field Outage Date):

When the Outage Type is "B" the color should vary from yellow to orange to red, where red indicate that most time has passed. Like this:

To get there you will nee to do the following. First define the symbology based on the outage type and assign the green and white colors to A and C. Then you will have to go into the second tap "vary the symbology by attribute":

To be able to create the colors for outage type "B", you will have enable the option "Allow symbol property connections":

When you do this, you can now create the color effect for outage type B based on the date. Click on the symbol for outage type B:

You will now be able to enter the properties, and activate the layers and to the right hand side you will see a grey icon that will allow you to define how to vary in this case the color. In my case the symbol is already blue since I already defined the attribute mapping:

This will open an interface where you can select an existing field or you can define an Arcade expression. I use the Arcade expression to define the scale of colors:

Since the colors should vary from yellow (most recent outages) to red (most dated outages) you can use the DateDiff function to calculate the difference between the current date and the date stored in the Outage Date field. Since to go from yellow, through orange to red you just vary the green intensity from 255 to 0, you can use a simple calculation. In my case my maximum time was 11 days so I divide the calculated days by 11 invert the result  and multiply by 255. Then I construct the text to return "rgb(255, green, 0)" and that is all. If your green value will be out of the range from 0 to 255, it will be limited to 0 - 255. 

Example Arcade expression:

var days = Abs(DateDiff(Now(), $feature.OutageDate, "days"));
var green = Round((1.0 - (days / 11.0)) * 255,0);
return "rgb(255," + green + ",0)";

Let me know if you run into any problems.

XanderBakker
Esri Esteemed Contributor

Hi Andy H ,

Did you have a chance of looking at the solution provided?

AndyH
by
New Contributor II

Been meaning come back in here and yes I did! It worked great! I changed it around to make the max at about 24 hrs and the rest would be whatever percentage of 24 hrs we were at, and so far I think it works just great. Thank you again!

XanderBakker
Esri Esteemed Contributor

Hi Andy H ,

I'm glad to hear that it worked for you. Thanks for letting me know.

0 Kudos