Select to view content in your preferred language

Serial chart - minimize # of categories using expressions?

422
4
Jump to solution
03-08-2026 02:24 PM
AdamCottrell
Frequent Contributor

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:

TypeDescriptor (additional field - unrelated)
Speed Limit: 5mph5
Speed Limit: 10mph63
Speed Limit: 15mph32
Speed Limit: 20mph80
Speed Limit: 25mph46
Warning: Dead end3
Warning: Bicycles10
Warning: Pedestrian8
Regulatory: Stop79
...and so onetc.

 

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!

TypeDescriptorNew field for Chart
Speed Limit: 5mph5Speed Limit
Speed Limit: 10mph63Speed Limit
Speed Limit: 15mph32Speed Limit
Speed Limit: 20mph80Speed Limit
Speed Limit: 25mph46Speed Limit
Warning: Dead end3Warning
Warning: Bicycles10Warning
Warning: Pedestrian8Warning
Regulatory: Stop79Regulatory
...and so onetc.etc.
0 Kudos
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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);

 

View solution in original post

0 Kudos
KenBuja
MVP Esteemed Contributor

This would return the first seven characters

attrs["Category"] = Left(f["Type"], 7);

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

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);

 

0 Kudos
AdamCottrell
Frequent Contributor

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.

 

0 Kudos
KenBuja
MVP Esteemed Contributor

This would return the first seven characters

attrs["Category"] = Left(f["Type"], 7);
0 Kudos
AdamCottrell
Frequent Contributor

Thank you, Ken!  This was extremely helpful and saved me a lot of hours!  I truly appreciate your assistance.

0 Kudos