Allow multiple categories to be grouped manually in a pie chart

3337
6
10-17-2018 09:46 AM
Status: Already Offered
Trippetoe
Occasional Contributor III

I'd like the ability to manually include multiple categories into a single slice in a pie chart. Currently categories can only be grouped together based on a minimum percentage threshold (for example, all categories with less than 5% of total can be grouped). 

One specific use case for this request is based on data generated from Survey123.  In our survey we have a multiple choice question. when multiple options are selected, Survey123 stores the selections as a comma separated list. According to esri tech support there is a known bug in Survey123 such that the options are not always listed in the same order. For example, if options A, B and C are selected, Survey123 could store the data as "A,B,C" or "B,A,C", or "C,B,A" and so on.  Each of those values are really the same thing, but if you create a pie chart with that data, you will get 3 separate slices.  I want to group those three values/categories into a single slice to correctly represent the data.

Another example that comes to mind - a survey of middle school students and the extra-curricular act ivies might include answers like:  track, basketball, drama club, art club, book club, jazz band, marching band, chess club, cooking club, none, etc.  I'd like to be able to group those many options into broad categories like Sports, Art, etc.  The pie chart with a few broad level categories, as opposed to many individual slices would be much nicer (i think).

6 Comments
DanteLee

I'm all for this idea, and I'd even propose extending this to all chart types.

FarrahPrewitt1

Does anyone know if Esri did any updates to this?

Tim-Woodfield

This would be useful for category selectors also. Being able to manually group options would be helpful for all of the widgets.

RichardLittlefield

I agree this would be helpful. You can group symbology values in ArcGIS Desktop, so same idea would be helpful here with Dashboards on the various charts. I have a project right now that it would have been helpful for the Pie Chart. 

The only way to accomplish this now would be to add new fields and edit the data to the grouping you want.

KenZiegler


This would be incredibly useful.  It is one thing holding back a project that I am currently working on.

patrickb
Status changed to: Already Offered

The ability to do something like this is provided with data expressions (available in ArcGIS Online and in a future release of ArcGIS Enterprise). A data expression will allow you to loop through your features and sort the strings. The basic idea is as follows:

//Create a dictionary to store intermediate results 
var sortedStrings = {
  fields: [
    { name: "OUT_STR_FLD", type: "esriFieldTypeString" },
    { name: "OUT_VAL_FLD", type: "esriFieldTypeInteger" }
  ],
  geometryType: "",
  features: [],
};

//Loop through the layer that needs its strings sorted 
var i = 0 
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '037799cbec1b40f2b1aa03c23b1cc91e', 0, ["*"], false);
for (var feat in fs) { 
    sortedStrings.features[i] = {
    attributes: {
      OUT_STR_FLD: sort(split(feat["STR_FLD"],',')),
      OUT_VAL_FLD: feat["VAL_FLD"]
    },
  };
  i++;
}

//Turn the intermediate results into a feature set and then group 
//by the newly sorted strings 
return GroupBy(FeatureSet(Text(sortedStrings)), ['OUT_STR_FLD'], 
       [{ name: 'SUM_FLD', expression: 'OUT_VAL_FLD', statistic: 'SUM' }]);  

Note: The above Arcade gets executed every time the dashboards loads and is really only recommended on small to medium size datasets. If your dashboard gets slow using the above approach, the suggestion would be to run a field calculation on the unsorted strings.