Select to view content in your preferred language

How to create graph on Dashboard from multiple choice string

1147
6
02-19-2026 04:34 AM
MiriamWebborn
Emerging Contributor

Hi there, 

First time posting on here. I keep running into what seem like limitations with the software but I am determined that there must be a work around. 

I have several Survey123 surveys which have multiple choice questions. The outputs from these questions are in a string e.g., 'banana, orange, apple'.

What I would like to do is create a pie or bar chart in ArcGIS Dashboards to display the number of times each choice in the multiple choice was individually selected across all submissions e.g., banana = 34, orange =26, apple = 54. 

I have recently discovered New Data Expression section in Dashboards and feel this must be the way. 

Can someone confirm this is how it would be done? If so, I will provide the details of my survey and would really appreciate some help with the code. 

Thanks in advance. 

0 Kudos
6 Replies
JenniferAcunto
Esri Regular Contributor

When you open the builder to create a data expression, there is link to several sample data expressions, including this one that handles the Survey123 multi-selects. It says it's for use in pie charts, but you can just use it in a serial chart just fine. 

SplitCategories(PieChart).md

You will need to make a few updates to work with your data.

1. If you are using ArcGIS Enterprise, use your enterprise URL

2. From top to bottom, survey data layer item id, survey data layer layer id, multi-select field name

3. Multi-select field name

JenniferAcunto_1-1771507179995.png

 

- Jen
0 Kudos
MiriamWebborn
Emerging Contributor

Hi @JenniferAcunto 

Thank you for answering my question so swiftly! I have already tried this but I am not sure why it doesn't work for me - maybe you can help me debug and work out what I am doing wrong?

A couple questions to make sure I am doing it right: 

1. the only things I need to change in the example code are the Portal (you highlighted as 1), FeatureSetByPortalItem (you highlighted as 2) and the field name (you highlighted as 3)?

2. Portal - mine should also be 'https://www.arcgis.com' because it is a feature layer hosted on ArcGIS Online?

3. The FeatureSetByPortalItem should be the hosted feature layer not any other layers or views as pictured in the attached screen shot showing form 'feature layers'?

4. The FeatureSetByPortalItem should be taken from this the URL highlighted in image 'FeatureSetByPortalItem'?

5. The FeatureSetByPortalItem is the section in bold in this link below?

https://services-eu1.arcgis.com/LgIVKFtcUmoHs3mV/arcgis/rest/services/service_f1156eb85ed043e48b60d5167342bdbc/FeatureServer

6. The field name should be 'why' see attached image of 'multiple choice question output' & 'multiple choice name of field'

Thank you for your help - I hope you can help me to get this to work. 

The errors shown in images relating to error 1 and 2. If you would like me to copy and paste script let me know. 

0 Kudos
MiriamWebborn
Emerging Contributor
 
// Reference layer using the FeatureSetByPortalItem() method.
var portal = Portal('https://www.arcgis.com')
var fs = FeatureSetByPortalItem(
    portal,
    'f1156eb85ed043e48b60d5167342bdbc',
    0,
    ['why'],
    false
);

// Create empty array for features and feat object
var features = [];
var feat;

// Split comma separated hazard types and store in dictionary.  
for (var feature in fs) {
    var split_array  =  Split(feature["why"], ',')
    var count_arr = Count(split_array)
    for(var i = 0; i < count_arr; i++ ){
        feat = {
            'attributes': {
                'split_choices': Trim(split_array[i])
            }
        }
        Push(features, feat);
}}

// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {
    'fields': [
        { 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
    'geometryType': '',
    'features': features
};

// Convert dictionary to featureSet.
var fs_dict = FeatureSet(choicesDict);

// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
       [{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);  
0 Kudos
JenniferAcunto
Esri Regular Contributor

You can get the item id from the survey data Item Details page. It can be found in the page URL or by expanding the details panel on the right.

2026-02-20_08-43-39.jpg

 

 
- Jen
0 Kudos
MiriamWebborn
Emerging Contributor

Hi Jen, 

Thank you so much! This is working now! Really appreciate your help, I have spent a long time trying to find other work arounds!

Thanks, 

Miriam

 

0 Kudos
JenniferAcunto
Esri Regular Contributor

Use 'Sum' as your statistic in the chart instead of 'Count'. 

- Jen
0 Kudos