I have a feature service in this format:
Trail_Name | Group1_Inspection | Group2_Inspection | Group3_Inspection |
Trail 1 | Not Inspected | Inspected | Inspected |
Trail 2 | Inspected | Inspected | Inspected |
I needed to re-arrange the data for graphing in a dashboard, so I figured out how to use a Data Expression to reshape the attribute table into this format:
Trail_Name | Inspection_Group | Inspection_Status |
Trail 1 | Group1 | Not Inspected |
Trail 2 | Group1 | Inspected |
Trail 1 | Group2 | Inspected |
And so on...
Essentially, this way I could graph by Inspection Group and split the data in the graph by Inspection Status so I could display in the dashboard how many groups have completed their various inspections. Assuming the method to the madness matters, you can see essentially how I did this in the code snippet at the end of the post. The code works, and I'm able to create a graph the way I wanted. However...
The issue I'm having is that my graph does not allow me the option to filter my map, based on column selection. When I try to configure the chart properties for filtering, it wants me to specify destination and target fields. Well, I retained trail name in an attempt to make this work, but it doesn't allow that as an option. So, I'm trying to figure out whether that was due to the way I split up my data through my data expression - or alternatively if it's just not possible after the data re-arrange. Anybody have any clues?
Thanks.
var portal = Portal('https://www.arcgis.com/');
var fs = FeatureSetByPortalItem(
portal,
'1234567890',
0,
[
'TRLNAME',
'Group1_Inspection',
'Group2_Inspection',
'Group3_Inspection'
],
false
);
var g1 = GroupBy(fs, ['Group1_Inspection', 'TRLNAME'], [{name: 'Count', expression: "1", statistic: 'COUNT'}])
var g2 = GroupBy(fs, ['Group2_Inspection', 'TRLNAME'], [{name: 'Count', expression: "1", statistic: 'COUNT'}])
var g3 = GroupBy(fs, ['Group3_Inspection', 'TRLNAME'], [{name: 'Count', expression: "1", statistic: 'COUNT'}])
var features = [];
var feat;
for (var g in g1) {
feat = {
attributes: {
TRLNAME: g['TRLNAME'],
inspection_group: 'Group1',
inspection_status: g['Group1_Inspection'],
Combined_Segment_count: g['Count']
}
};
Push(features,feat);
}
for (var g in g2) {
feat = {
attributes: {
TRLNAME: g['TRLNAME'],
inspection_group: 'Group2',
inspection_status: g['Group2_Inspection'],
Combined_Segment_count: g['Count']
}
};
Push(features,feat);
}
for (var g in g3) {
feat = {
attributes: {
TRLNAME: g['TRLNAME'],
inspection_group: 'Group3',
inspection_status: g['Group3_Inspection'],
Combined_Segment_count: g['Count']
}
};
Push(features,feat);
}
var fsDict = {
'fields': [
{'name':'TRLNAME', 'type':'esriFieldTypeString'},
{'name':'Inspection_Group', 'type':'esriFieldTypeString'},
{'name':'Inspection_Status', 'type':'esriFieldTypeString'},
{'name':'Combined_Segment_Count', 'type':'esriFieldTypeInteger'}
],
'geometryType': '',
'features': features,
}
return FeatureSet(Text(fsDict));
I can't see a reason why this would happen. I have data expression layers filtering map layers in exactly the way you are attempting to do yourself.
Is it, by chance, a Map Image layer, as opposed to a Feature Layer?
When you attempt to add the action between the chart and the map, what, if anything, do you see?
Hi Josh - I actually used some of your other responses here on GeoNet to work out how to re-arrange my data; in case you don't hear it enough, thanks for being a contributor. I'm sure I'm not alone in having learned from your experience/expertise.
I'm talking to a feature layer, not a map image layer, but I did figure out the issue. I was charting off of Inspection Group and Inspection Status. I thought Trail Name could still be used as a filter, but I overestimated the ability of the Dashboard in that respect. When I charted off of Trail Name, the filter worked.
One additional issue I noticed is that, when attempting to filter the chart based on map extent, the whole chart breaks down. It will just return 'No Data'. To the best of your knowledge, is that just a limitation of the data expressions? I'm guessing it's just too much processing to occur any time the map is adjusted.
Glad you figured it out!
The key to that second issues is this:
geometryType: ''
Without including the geometry of your features, there's nothing for the map to act against.
You can include the geometry in your output, but your expression will suffer decreased performance. Since you're grouping, you'd need to somehow perform a Union somewhere in your expression, and that kind of thing can get pretty "expensive" in terms of compute time.