Select to view content in your preferred language

Filterable chart based on calculation of multiple fields in same layer

325
0
11-18-2024 06:39 PM
Labels (1)
JanetBrewster1
Regular Contributor

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
116025299630.5348262857524280
2109246593581.8404595842177971
369862728640.95879995608256472
462012700.48818897637795283
517095293640.58217545293556744
612965220880.5869703006157195
7166435140.47353443369379626
812748166450.76587563832982877
911461386420.296594379172920648
10171052110.32815198618307439
11127337930.3356182441339309310
12846590.127465857359635811
13102324330.420468557336621512
1539536317821.243974576804480513
1628672269771.062831300737665514
1711571130440.887074517019319315
1822342450250.4962132148806218716
19480546711.02868764718475717
20210334230.614373356704645118

 

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.

JanetBrewster1_1-1731982929549.png

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

0 Kudos
0 Replies