I am attempting to create an arcade code that will censor data in a serial chart on a dashboard. I am very new to arcade and there seems to be little information on how to do this or if this is possible. From lots of research I have put together some code, but the layer is marked as "unable to execute arcade script." Any tips or critiques of what I have or where I can find examples of what I am trying to do are much appreciated!
My code is below:
var fsportal = Portal("https://www.arcgis.com/");
var fs = FeatureSetByPortalItem(fsportal, "dfc071575e924d5d88cb851eab914222", 0, ['Total_Daily_Cases','Hispanic_or_Latino',
'Not_Hispanic_or_Latino', 'Unknown_Ethnicity', 'Ethnicity_Not_Reported',
'Black_or_African_American', 'White_Race', 'Other_Race',
'Native_Hawaiian_or_Other_Pacific_Islander_Race', 'Asian_Race',
'American_Indian_or_Alaskan_Native_Race', 'Unknown_Race',
'Race_Not_Reported','Unknown_Age_Group', '00_17_Age_Group',
'18_29_Age_Group','30_39_Age_Group','40_49_Age_Group',
'50_64_Age_Group','65_74_Age_Group','75__Age_Group','Year', false]);
if (IsEmpty(fs)) {
return "No data available for this query.";
} else {
return "Feature Set successfully retrieved.";
}
var cnsrvalue = feature(fs,'Total_Daily_Cases')
if (cnsrvalue <= 5) {
return "suppressed";
} else {
return Text(cnsrvalue); // Return the actual value as a string
}
var CnsrDict = {
fields: [
{name: 'Total_Daily_Cases', type: 'esriFieldTypeInteger'},
{name: 'Hispanic_or_Latino', type: 'esriFieldTypeInteger'},
{name: 'Not_Hispanic_or_Latino', type: 'esriFieldTypeInteger'},
{name: 'Unknown_Ethnicity', type: 'esriFieldTypeInteger'},
{name: 'Ethnicity_Not_Reported', type: 'esriFieldTypeInteger'},
{name: 'Black_or_African_American', type: 'esriFieldTypeInteger'},
{name: 'White_Race', type: 'esriFieldTypeInteger'},
{name: 'Other_Race', type: 'esriFieldTypeInteger'},
{name: 'Native_Hawaiian_or_Other_Pacific_Islander_Race', type: 'esriFieldTypeInteger'},
{name: 'Asian_Race', type: 'esriFieldTypeInteger'},
{name: 'American_Indian_or_Alaskan_Native_Race', type: 'esriFieldTypeInteger'},
{name: 'Unknown_Race', type: 'esriFieldTypeInteger'},
{name: 'Race_Not_Reported', type: 'esriFieldTypeInteger'},
{name: 'Unknown_Age_Group', type: 'esriFieldTypeInteger'},
{name: '00_17_Age_Group', type: 'esriFieldTypeInteger'},
{name: '18_29_Age_Group', type: 'esriFieldTypeInteger'},
{name: '30_39_Age_Group', type: 'esriFieldTypeInteger'},
{name: '40_49_Age_Group', type: 'esriFieldTypeInteger'},
{name: '50_64_Age_Group', type: 'esriFieldTypeInteger'},
{name: '65_74_Age_Group', type: 'esriFieldTypeInteger'},
{name: '75__Age_Group', type: 'esriFieldTypeInteger'},
{name: 'Year', type: 'esriFieldTypeInteger'},
{name: 'cnsrvalue', type: 'esriFieldTypeString'}
]
};
var index = 0;
return Featureset(Text(CnsrDict));
When posting a question with code, please use the "Insert/Edit code sample" button
You can hide the records that don't have enough daily cases simply by using the Filter function.
var fsportal = Portal("https://www.arcgis.com/");
var fs = FeatureSetByPortalItem(
fsportal,
"dfc071575e924d5d88cb851eab914222",
0,
[
"Total_Daily_Cases",
"Hispanic_or_Latino",
"Not_Hispanic_or_Latino",
"Unknown_Ethnicity",
"Ethnicity_Not_Reported",
"Black_or_African_American",
"White_Race",
"Other_Race",
"Native_Hawaiian_or_Other_Pacific_Islander_Race",
"Asian_Race",
"American_Indian_or_Alaskan_Native_Race",
"Unknown_Race",
"Race_Not_Reported",
"Unknown_Age_Group",
"00_17_Age_Group",
"18_29_Age_Group",
"30_39_Age_Group",
"40_49_Age_Group",
"50_64_Age_Group",
"65_74_Age_Group",
"75__Age_Group",
"Year"
],
false
);
Filter(fs, "Total_Daily_Cases <= 5")
Thank you! How can I make the data label in the serial chart "suppressed" if the value is <= 5?
Another way you can do is to change all the values for the records you want suppressed to -1 (or another value) . You'd have to put a note in the chart saying what that value means. Here's an example, using a sample Esri dataset. This show the value that's being checked, but not the other values for each record. If you don't want to show that, remove lines 19-23 and uncomment line 24.
var fields = ["AVGHHSZ_CY", "EDUC01_CY", "EDUC02_CY"];
// Returns the first feature in the layer
var fs = Top(
FeatureSetByPortalItem(
Portal("https://www.arcgis.com"),
"7b1fb95ab77f40bf8aa09c8b59045449",
0,
fields,
false
),
99
);
var features = [];
//return theDict
for (var f in fs) {
var attDict = {};
for (var a in fields) {
if (fields[a] == "AVGHHSZ_CY") {
attDict[fields[a]] = f[fields[a]];
} else {
attDict[fields[a]] = IIf(f["AVGHHSZ_CY"] > 3, f[fields[a]], -1);
}
//attDict[fields[a]] = IIf(f["AVGHHSZ_CY"] > 3, f[fields[a]], -1);
}
Push(features, { attributes: attDict });
}
return FeatureSet(
{ fields: Schema(fs).fields, geometryType: "", features: features }
);
The last item in the field list for FeatureSetByPortalItem is a boolean value, not a field name. I think you mistyped the return geometry parameter, the fixed line is:
var fs = FeatureSetByPortalItem(
fsportal,
"dfc071575e924d5d88cb851eab914222",
0, [
"Total_Daily_Cases",
"Hispanic_or_Latino",
"Not_Hispanic_or_Latino",
"Unknown_Ethnicity",
"Ethnicity_Not_Reported",
"Black_or_African_American",
"White_Race",
"Other_Race",
"Native_Hawaiian_or_Other_Pacific_Islander_Race",
"Asian_Race",
"American_Indian_or_Alaskan_Native_Race",
"Unknown_Race",
"Race_Not_Reported",
"Unknown_Age_Group",
"00_17_Age_Group",
"18_29_Age_Group",
"30_39_Age_Group",
"40_49_Age_Group",
"50_64_Age_Group",
"65_74_Age_Group",
"75__Age_Group",
"Year"
],
false
);
Good catch! I fixed that in my reply