Select to view content in your preferred language

Legend’s sorting order for Graduated Colors

207
2
03-18-2024 09:58 AM
Jeff-Reinhart
New Contributor III

Two questions:

(1) Why does a Feature Layer (FL) with graduated colors (e.g. unemployment data) default to descending order in the legend?

(2) What is the best way to instead show the classes in ascending order in the legend?

Please see this unemployment data service and this codepen for an example. Note in the service that the JSON for the renderer lists the classes in ascending order (starts at less than 2.4, ends at greater than 5.8). Yet, when shown in the legend, it is shown in descending order (top is greater than 5.8, bottom is less than 2.4).

I am working on my own FL that is exhibiting the same behavior (I don’t have a quick way to publicly publish this layer). On my FL, I have tried reversing the order in the ArcPro project and republishing. This doesn't change the order in the service's renderer JSON, and as expected, the legend still shows in descending order in the Maps SDK.

I have looked through the Feature Layer API Reference and I am not seeing any properties or methods that could help. A legendSort property seems to be missing. I will look into using Arcade, but that seems overkill.

0 Kudos
2 Replies
Jeff-Reinhart
New Contributor III

Solved it on my own... was actually pretty easy:

myFeatureLayer.renderer.classBreakInfos = myFeatureLayer.renderer.classBreakInfos.reverse()
0 Kudos
Jeff-Reinhart
New Contributor III

Still curious as to why these layers default to descending order in the legend and why there is not a legendSort property.

0 Kudos