I am trying to create a serial chart in ArcGIS Dashboard (Enterprise v12) but the unique number of categories is almost 360 and the bar chart is too overwhelming with this many values. I would like to minimize it by using data expressions but not sure how to do it. For example, current data is setup like:
| Type | Descriptor (additional field - unrelated) |
| Speed Limit: 5mph | 5 |
| Speed Limit: 10mph | 63 |
| Speed Limit: 15mph | 32 |
| Speed Limit: 20mph | 80 |
| Speed Limit: 25mph | 46 |
| Warning: Dead end | 3 |
| Warning: Bicycles | 10 |
| Warning: Pedestrian | 8 |
| Regulatory: Stop | 79 |
| ...and so on | etc. |
I would like to group these in the chart as a single category by "Speed Limit*" so the expression would create a table like this below. Is this possible? If so then I could really use the help and greatly appreciate it!
| Type | Descriptor | New field for Chart |
| Speed Limit: 5mph | 5 | Speed Limit |
| Speed Limit: 10mph | 63 | Speed Limit |
| Speed Limit: 15mph | 32 | Speed Limit |
| Speed Limit: 20mph | 80 | Speed Limit |
| Speed Limit: 25mph | 46 | Speed Limit |
| Warning: Dead end | 3 | Warning |
| Warning: Bicycles | 10 | Warning |
| Warning: Pedestrian | 8 | Warning |
| Regulatory: Stop | 79 | Regulatory |
| ...and so on | etc. | etc. |
Solved! Go to Solution.
Here's one way to create that new field.
This takes the Schema of your original FeatureSet (line 9) and adds the additional field "Category" (line 10). It creates a dictionary for a new FeatureSet (lines 12-16), then loops through the records in the original Featureset (line 17) and copying all the attributes (lines 20-22). For the new "Category" field, it takes the value from the "Type" attribute, splits it into an array, and extracts the text before the colon (line 23). The attributes are added into a new feature (line 25) and a new FeatureSet is created from the dictionary (line 27).
var fs = FeatureSetByPortalItem(
Portal("yourPortal"),
"yourItem",
0,
["*"],
false
);
var theSchema = Schema(fs);
Push(theSchema.fields, { name: "Category", type: "esriFieldTypeString" });
//return theSchema;
var temp_dict = {
fields: theSchema["fields"],
geometryType: Schema(fs).geometryType,
features: []
};
for (var f in fs) {
var attrs = {};
for (var attr in f) {
attrs[attr] = f[attr];
}
attrs["Category"] = Split(f["Type"], ":")[0];
Push(temp_dict["features"], { attributes: attrs, geometry: Geometry(f) });
}
return Featureset(temp_dict);
This would return the first seven characters
attrs["Category"] = Left(f["Type"], 7);
Here's one way to create that new field.
This takes the Schema of your original FeatureSet (line 9) and adds the additional field "Category" (line 10). It creates a dictionary for a new FeatureSet (lines 12-16), then loops through the records in the original Featureset (line 17) and copying all the attributes (lines 20-22). For the new "Category" field, it takes the value from the "Type" attribute, splits it into an array, and extracts the text before the colon (line 23). The attributes are added into a new feature (line 25) and a new FeatureSet is created from the dictionary (line 27).
var fs = FeatureSetByPortalItem(
Portal("yourPortal"),
"yourItem",
0,
["*"],
false
);
var theSchema = Schema(fs);
Push(theSchema.fields, { name: "Category", type: "esriFieldTypeString" });
//return theSchema;
var temp_dict = {
fields: theSchema["fields"],
geometryType: Schema(fs).geometryType,
features: []
};
for (var f in fs) {
var attrs = {};
for (var attr in f) {
attrs[attr] = f[attr];
}
attrs["Category"] = Split(f["Type"], ":")[0];
Push(temp_dict["features"], { attributes: attrs, geometry: Geometry(f) });
}
return Featureset(temp_dict);
This worked almost perfectly. I have some records that do not have the " : ". Is there a way to change line 23 split from ":" to a number of characters? For example, split if the first 7, or so, characters that match. I'm not sure if the left() will work here within the split function.
This would return the first seven characters
attrs["Category"] = Left(f["Type"], 7);
Thank you, Ken! This was extremely helpful and saved me a lot of hours! I truly appreciate your assistance.