Two fields in one graph - Separating the data (Multiple choice)

257
1
10-11-2023 10:09 AM
DianaVelo
New Contributor

Hello, I require assistance regarding the addition of the second field.

Currently, I have race and ethnicity fields that need to be displayed together in a serial chart. I have successfully managed to segregate the data based on race, as that particular question allows for multiple choices from different races. I aimed to obtain individual counts for each race while also considering the cases where respondents select multiple races. However, I am unsure of how to incorporate the Hispanic/Latino category from my ethnicity question on the list. Despite it seemingly being a simple task, I have been unable to generate any ideas on how to achieve this.

I sincerely appreciate any help you can offer.

 

This is what i have so far:

// Reference layer using the FeatureSetByPortalItem() method.
var fs = FeatureSetByPortalItem(Portal('https://address'), '11f111cb111b111daf1b1d11111ee111', 0, ['*'], true,);

// Empty dictionary to capture each basic need reported as separate rows.
var choicesDict = {'fields': [
{ 'name': 'date_of_contact', 'type': 'esriFieldTypeDate'},
{ 'name': 'race', 'type': 'esriFieldTypeString'},
],
                   
'geometryType': 'esriGeometryPoint',

"spatialReference": {
  "wkid": 102100,
  "latestWkid": 3857
 },
'features': []
};

// Loop through the FeatureSet and store attributes into a dictionary.
var index = 0;
for (var feature in fs) {

    // Split comma separated basic needs and store in dictionary.
    var split_array  =  Split(feature["race"], ',')
    var count_arr = Count(split_array)
    var raceVariable = iif(count_arr == 1, feature["race"], "Multiple Races")
   
    // Loop through each of the select multiple choice selections to create an entry in the dictionary.
    for(var i = 0; i < count_arr; i++ ){

        choicesDict.features[index] = {
        'geometry': {
                'x': Geometry(feature)["X"],
                'y': Geometry(feature)["Y"]
            },
            attributes: { date_of_contact: DateDiff(feature["date_of_contact"], Date(1970, 0, 1, 0, 0, 0), "milliseconds"),
        race: raceVariable
             
            }}
        index++;
}}

// Convert dictionary to featureSet.
return FeatureSet(Text(choicesDict));
 
And this is the graph i can get from that.
DianaVelo_0-1697043946417.png

 

Tags (3)
0 Kudos
1 Reply
ArielLow2146
Occasional Contributor II
0 Kudos