Hello All,
I figured out some code to give me the results I need. However, I cannot get this new serial chart to adjust as I use various Selectors in my Dashboard.
For example, I have a Location Selector where the user can choose one or more of the 20 locations and all the other charts and indicators in the Dashboard filter when a location(s) is chosen. However, this new chart does NOT change, regardless of the Actions I have set up (and actually, it won't save the Actions that I do select).
Do the Actions only work on charts that have not been created by Data Expressions?
// Purpose: Divide two fields from the same layer to use in Dashboard's Serial Chart
//Access AGOL, using all attributes from one layer
var portal = Portal('https://arcgis.com');
var fs = FeatureSetByPortalItem(
portal,
'xyzx',
0,
['*'],
false
);
//Create empty dictionary
var ratioDict = {
'fields': [
{'name': 'CPUE', 'type': 'esriFieldTypeDouble'},
{'name': 'LocationCode', 'type': 'esriFieldTypeDouble'},
//{'name': 'SHRC_Year', 'type': 'esriFieldTypeString'},
//{'name': 'Month', 'type': 'esriFieldTypeString'},
//{'name': 'SHRC_Month_Num', 'type': 'esriFieldTypeDouble'},
{'name': 'TotalSteelhead', 'type': 'esriFieldTypeDouble'},
{'name': 'TotalTrips', 'type': 'esriFieldTypeDouble'},
],
'geometryType': '',
'features': []
};
var index = 0
//Loop through features in the featureset to populate dictionary
for (var feature in fs) {
ratioDict.features[index++] = {
'attributes': {
'LocationCode': feature ['LocationCode'],
//'SHRC_Year': feature ['SHRC_Year'],
//'Month': feature ['Month'],
//'SHRC_Month_Num': feature ['SHRC_Month_Num'],
'TotalSteelhead': feature ['TotalSteelhead'],
'TotalTrips': feature ['TotalTrips']
}
}
};
var fsd = FeatureSet(ratioDict)
//Get the sums grouped by a field
var fs_sums = GroupBy(fsd, ['LocationCode'], [
{name: 'TS_sum', expression: 'TotalSteelhead', statistic: 'SUM'},
{name: 'TT_sum', expression: 'TotalTrips', statistic: 'SUM'},
])
//Use GroupBy again, grouping by the same field but adding the needed ratio
var fs_quotient = GroupBy(fs_sums, ['LocationCode'], [
{name: 'TS_sum', expression: 'TS_sum', statistic: 'SUM'},
{name: 'TT_sum', expression: 'TT_sum', statistic: 'SUM'},
{name: 'CPUE', expression: 'TS_sum / TT_sum', statistic: 'SUM'}
]);
return fs_quotient
Yes, it's giving the correct results:
featureSet: LocationCode TS_sum TT_sum CPUE ROW__ID
|
My Dashboard, with 3 Selectors that filter all the charts and indicators except for the one in lighter blue (the one created by my above data expression). Ideally, the new chart would adjust when any Selector is used, and I get why only the Location Selector might work (since that's what the data expression is aggregated on), but it doesn't work. And unfortunately, the Statistics available in the Data Options for the chart are limited and don't allow me to do the calculation that I want, hence the need to create the data expression.
Am I trying to do something too complicated for the current iteration of Dashboards? I would love some feedback if anyone has thoughts. Thanks!
Janet