I am trying to create breaks within a certain data field so that, within a Dashboard, a can have a bar chart that shows those bins. I want to do an Arcade expression rather than adjusting the data in a separate field, because these breaks are subject to change as the Dashboard is reviewed. To me this seems like it should be very easy, but nothing works and most frustratingly, there doesn't seem to be a way to actually see what isn't working, as you could on any IDE. Esri documentation is also, as usual for them, terrible. So I am hoping someone can help me. So far I have been working through ChatGPT (I know, I know...) to come up with something.
All I am trying to do is that a field "Taxlot_Acres", which as can be surmised by the name, is the area in acres of a taxlot. I want a bar chart attached to the layer that shows count of taxlots in each bin. This bar chart will dynamically reflect other filters on the layer. Here is what I have come up with so far:
// Connect to your hosted feature layer by portal item ID and layer index
var portal = Portal("https://www.arcgis.com");
var fs = FeatureSetByPortalItem(
portal,
"012345ABCEDF6789", // Your item ID
2, // Layer index
["Taxlot_Acres"], // Only bring in needed field
false // Exclude geometry (faster)
);
// Define output schema
var schema = {
fields: [
{ name: "bin", type: "esriFieldTypeString" },
{ name: "count", type: "esriFieldTypeInteger" }
]
};
// Initialize bin counters
var bins = {
"<1": 0,
"1–4": 0,
"5–9": 0,
"10–24": 0,
"25+": 0
};
// Loop through features and apply binning logic
for (var f in fs) {
var acres = f["Taxlot_Acres"];
if (acres == null) { continue; }
if (acres < 1) {
bins["<1"] += 1;
} else if (acres < 5) {
bins["1–4"] += 1;
} else if (acres < 10) {
bins["5–9"] += 1;
} else if (acres < 25) {
bins["10–24"] += 1;
} else {
bins["25+"] += 1;
}
}
// Convert dictionary to FeatureSet
var output = [];
for (var b in bins) {
Push(output, {
attributes: {
bin: b,
count: bins[b]
}
});
}
return FeatureSet(Text(output), schema);
I feel like I am almost there, though which GPT and Esri's lack of quality documentation, can't be sure of that. Can anyone advise? I would be so grateful.