Combining Multiple Categories in a Serial Chart

1576
2
Jump to solution
02-23-2022 07:26 AM
DaveBodak
Occasional Contributor

We are working on a hydrant inspection program to be integrated with AGOL. The program has two crew members in the same vehicle where they will go to inspect and service hydrants, with 8 crew members in total (so 4 groups). As a part of the hydrant inspection form, there are two fields for the inspectors; "Inspector 1" and "Inspector 2", one for each of them to show that they were the ones who took place in the inspection.

As a part of this, I am designing a dashboard to display all types of information on the program. One of the elements is a serial chart showing the number of hydrants that an inspector has been responsible for:

DaveBodak_0-1645629581965.png

The issue comes when attempting to combine this number for the two fields, this chart is only showing the inspections done by the "Inspector 1" field in this case. We are looking for a way to combine the "Inspector 1" and "Inspector 2" fields to count the number of times that an inspector is present in each field.

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

 

It sounds like you need a Data Expression.

There are lots of ways to do this, but the simplest is to go through each record and add each attribute to a new FeatureSet as its own row.

If you want the chart to interact with other widgets, like filtering by date / hydrant / etc., it gets more complex, but here's the simple version:

var portal = Portal('https://www.arcgis.com');

// Inspections layer
var fs = FeatureSetByPortalItem(
    portal,
    'itemid',
    0, // or whatever layer index for the layer
    [
        'inspector_1',
        'inspector_2'
    ],
    false
);

// List of inspectors per field per feature; empty for now
var out_dict = {
    fields: [{name: 'inspector', type: 'esriFieldTypeString'}],
    geometryType: '',
    features: []
}

// Iterate over each feature in the layer
for (var f in fs){
    
    // Add inspector 1 to out_dict
    Push(
        out_dict['features'],
        {attributes: {inspector: f['inspector_1']}}
    )
    
    // Add inspector 2 to out_dic
    Push (
        out_dict['features'],
        {attributes: {inspector: f['inspector_2']}}
    )
}

// Return populated out_dict as FeatureSet
return FeatureSet(Text(out_dict))

 

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

 

It sounds like you need a Data Expression.

There are lots of ways to do this, but the simplest is to go through each record and add each attribute to a new FeatureSet as its own row.

If you want the chart to interact with other widgets, like filtering by date / hydrant / etc., it gets more complex, but here's the simple version:

var portal = Portal('https://www.arcgis.com');

// Inspections layer
var fs = FeatureSetByPortalItem(
    portal,
    'itemid',
    0, // or whatever layer index for the layer
    [
        'inspector_1',
        'inspector_2'
    ],
    false
);

// List of inspectors per field per feature; empty for now
var out_dict = {
    fields: [{name: 'inspector', type: 'esriFieldTypeString'}],
    geometryType: '',
    features: []
}

// Iterate over each feature in the layer
for (var f in fs){
    
    // Add inspector 1 to out_dict
    Push(
        out_dict['features'],
        {attributes: {inspector: f['inspector_1']}}
    )
    
    // Add inspector 2 to out_dic
    Push (
        out_dict['features'],
        {attributes: {inspector: f['inspector_2']}}
    )
}

// Return populated out_dict as FeatureSet
return FeatureSet(Text(out_dict))

 

- Josh Carlson
Kendall County GIS
DaveBodak
Occasional Contributor

This worked great, thank you very much!

0 Kudos