Hello everyone,
I am working on a dashboard that reports the activities of stakeholders, using data from Survey123, and my client is asking for more dynamic graphs. My problem is with the Multiple Choice responses using Survey123. I want to graph each response option category separately, with the number of responses for each category, but with the built-in options, the graphs (serial and pie chart) produce a unique category for each of the 64 stakeholder responses with the multiple choices separated by commas. I've attached a photo of what this looks like, as well as what I want the graph to look like, as it does in Survey123's "Analyze" tab.
It sounds like I need to use Arcade for this. I found a link to an example expression in a separate post and gave it a try: https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/SplitCategories(PieChart).md
I changed the code to this:
// Reference layer using the FeatureSetByPortalItem() method.
var portal = Portal('https://www.arcgis.com')
var fs = FeatureSetByPortalItem(
portal,
'4a4974e1b74a45b2bbfc48d95c431e88',
0,
['GEO_focus'],
false
);
// Empty dictionary to capture each choice reported as separate rows.
var choicesDict = {'fields': [{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '', 'features': []};
var index = 0;
// Split comma separated choices and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature["GEO_focus"], ',')
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
choicesDict.features[index++] = {
'attributes': { 'split_choices': Trim(split_array[i]),
}
}}}
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
What I want is for the ecosystem types to appear on the x axis with the counts on the y axis. I've attached photos for what this expression translates into in graphic form in the dashboard. I'm not a programmer, so any help would be very much appreciated.
Thank you in advance!
@XavierBustos