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:
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.
Solved! Go to Solution.
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))
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))
This worked great, thank you very much!
Hello @jcarlson , I am trying to do the same thing that @DaveBodak did a couple of years ago. My task is to put data from four different fields into one: Equipment1...Equipment4 --> Equipment so I can show proportional usage per feature using a pie chart in a Dashboard. The Arcade code is attached, adapted from @jcarlson 's code above - my real portal address is different but all else should work. If anyone can help me sort this out I'd be very grateful!! Many thanks.