If the survey team is currently out in the field collecting data, is there a way to display the domains as 0 for a pie chart? legend I was trying to create an arcade expression, but the legend still doesn't want to list the domains that have 0. If not in a pie chart, is there another way to display 0 for domains with no records in ArcGIS Dashboards?
// Portal and item/layer IDs
var p = 'https://testurl';
var itemID = 'itemID'; // Item ID for the Water_Meter_v3 layer
var layerID = 0; // Layer index
// Domain values for 'cust_material_type'
var domainValues = [
{ "code": "Lead", "name": "Lead" },
{ "code": "GRR", "name": "Galvanized Steel" },
{ "code": "PVC", "name": "PVC" },
{ "code": "PE", "name": "PE" },
{ "code": "Copper", "name": "Copper" },
{ "code": "Braided Metal", "name": "Braided Metal" },
{ "code": "Unknown", "name": "Unknown to be verified" },
{ "code": "Non-Lead", "name": "Non-Lead" }
];
// Access the feature layer using FeatureSetByPortalItem and filter by `to_inventory`
var fs = FeatureSetByPortalItem(
Portal(p),
itemID,
layerID,
['cust_material_type', 'to_inventory'], // Fields to include
false
);
// Apply a filter to only include records where `to_inventory` is "Yes" or "TBD"
var filteredFs = Filter(fs, "to_inventory IN ('Yes', 'TBD')");
// Initialize a dictionary to store counts for each domain value
var domainCounts = {};
// Initialize all domain counts to 0
for (var i in domainValues) {
var code = domainValues[i]["code"];
domainCounts[code] = 0;
}
// Loop through the filtered features and count occurrences of each material type
for (var f in filteredFs) {
var materialType = f["cust_material_type"];
if (materialType != null && HasKey(domainCounts, materialType)) {
domainCounts[materialType] += 1;
}
}
// Create data schema
var Dict = {
'fields': [
{'name': 'cust_material_type', 'type': 'esriFieldTypeString'},
{'name': 'description', 'type': 'esriFieldTypeString'},
{'name': 'count', 'type': 'esriFieldTypeInteger'}
],
'geometryType': '',
'features': []
};
// Populate the data schema with the counts
for (var i in domainValues) {
var code = domainValues[i]["code"];
var name = domainValues[i]["name"];
var count = domainCounts[code]; // Retrieve count from domainCounts
// If count is undefined, set it to 0
if (count == null) {
count = 0;
}
Push(Dict.features, {
'attributes': {
'cust_material_type': code,
'description': name,
'count': count
}
});
}
// Return the featureset
return FeatureSet(Text(Dict));
It's interesting, the chart "sees" the other values, but when there's nothing to render for the Pie Chart, it won't include it in the legend.
A serial chart will show the empty values, though:
I think it's just a default setting on the pie chart, probably nothing you can do about it without something kinda hacky like making an SVG pie chart from scratch.