Arcade: how to change color in only one of the two stacked labels?

8447
9
Jump to solution
07-21-2017 04:57 PM
MilaAlvarez
New Contributor III

I was wondering if Arcade allows you to add color to a part of your label. Here is what I am trying to show in my label:

1.2M
(25k)
 
And here is the code for showing both labels in black:
Text(round(number($feature.WUI_Houses/1000000),1), "#,###.#") + Text("M")+ TextFormatting.NewLine + Text("(") + Text(round(number($feature.WUI_Seas_H/1000),0), "#,###.#") + Text("k") + Text(")")
 
I need to help to find out what is the code for changing color in the the second label only. Using ArcPro.
 
Many thanks!
 
Mila
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

I notice that you are labeling polygons. When labeling polygons you don't have the option to define the labels. You could extract the label points from the polygons and label the points instead. This could be achieved using Feature To Point—Data Management toolbox | ArcGIS Desktop (which requires an advanced license). It you don't have an Advanced license level, I can share a script that allows to create the label points using a Basic license. 

The disadvantage will be that if you are zoomed in and the label point is outside the visible extent, there will be no label for that polygon visible. 

The help (Create labels—ArcGIS Online Help | ArcGIS ) states completely at the end that the "Map Viewer does not support multiline labeling". There is an idea here: More options/controls on labeling features on webmaps, such as scale dependency and stacking that asks for stacked labels and was marked as implemented, but was only partially implemented.

Maybe KGerrow-esristaff can tell us a little more if this is on the roadmap. .

View solution in original post

9 Replies
XanderBakker
Esri Esteemed Contributor

Sure you can:

See the help: Text formatting tags—ArcGIS Pro | ArcGIS Desktop 

The formula that I applied was:

Round($feature.Total/1000,1) + 'M' + TextFormatting.NewLine + '<CLR red = "255">(' + Round($feature.Mean/10,0) + 'k)</CLR>'

Please note that my field names and data ranges differ.

MilaAlvarez
New Contributor III

Thank you so much for your quick response.

Your fomula works great in ArcPro, but when I use it in ArcGIS online to

host a map that I am using in a story map, it does not work. Here is how it

looks:

It seems like AOL does not stack labels, nor show the different colors. Is

that the case? Any advice?

Thank you!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Apparently color tags and multiline labels are not supported (yet) in ArcGIS Online. Let me test something and I get back to you.

0 Kudos
XanderBakker
Esri Esteemed Contributor

The only thing I can think of for the moment is to load the layer twice and define the red and black labels separately:

In this case using the middle right position for the red label and the top right position for the black label. Color can be defined in the create label interface. 

Each layer should have its own expression:

and

Two layer in the map:

MilaAlvarez
New Contributor III

Your images show exactly what I want to do! This is a great idea, but where

do you get the alignment commands (alineacion) that you show in your

pictures? If you go to ArcGIS online, the only option I see after "text"

and "halo" is the "visibility range". Am I missing something?

Thank you again for taking the time to help!

0 Kudos
XanderBakker
Esri Esteemed Contributor

I notice that you are labeling polygons. When labeling polygons you don't have the option to define the labels. You could extract the label points from the polygons and label the points instead. This could be achieved using Feature To Point—Data Management toolbox | ArcGIS Desktop (which requires an advanced license). It you don't have an Advanced license level, I can share a script that allows to create the label points using a Basic license. 

The disadvantage will be that if you are zoomed in and the label point is outside the visible extent, there will be no label for that polygon visible. 

The help (Create labels—ArcGIS Online Help | ArcGIS ) states completely at the end that the "Map Viewer does not support multiline labeling". There is an idea here: More options/controls on labeling features on webmaps, such as scale dependency and stacking that asks for stacked labels and was marked as implemented, but was only partially implemented.

Maybe KGerrow-esristaff can tell us a little more if this is on the roadmap. .

KellyGerrow
Esri Frequent Contributor

Hi,

This functionality will be added as part of the Map Viewer re-design project. Currently, stacking labels is not supported in the 3X JavaScript API, but will be in the 4x API. This is on the roadmap but will still be quite a few releases away.

-Kelly

MilaAlvarez
New Contributor III

Thank you so much Xander, that is a brilliant idea!!

0 Kudos
XanderBakker
Esri Esteemed Contributor

You're welcome and as Kellymentioned, it is on the roadmap, but it will take a while.

Just remember that if you have large polygons and only generate a single label point for each polygon, you will not see many labels when zoomed in.

It this answered the question, could you mark the post that answered your question as the correct answer?

Thanks in advance.