Select to view content in your preferred language

How to aggregate layer's data for use in Dashboard stacked chart

319
1
Jump to solution
06-07-2024 01:38 PM
JanetBrewster1
New Contributor III

Hello All,

I have a large data layer that I am using in a Dashboard, which includes a map, multiple selectors, indicators, and bar charts -- all derived from the one data layer and linked by Actions, and working fine. I would like to create a stacked chart, but am not able to do that out-of-the-box given the data layer's structure, so I'm trying to create a Data Expression that would help. I am new to Arcade...but I think I need to create a new feature set that sums up the data, and base my stacked chart on that. In playing around, I was able to make this work within the popup area of the map that's in the Dashboard:

 

//Summing numbers using a different data layer

var fs = FeatureSetByName($map, "TestData 2019 2021",['Month_', 'Month_Num', 'LocationCode','HatcheryKept', 'HatcheryReleased', 'WildReleased'])

// Group counts by month 
var fsGp = GroupBy(fs, 
  [ //fields/expressions to group statistics by -- see GroupBy reference https://developers.arcgis.com/arcade/function-reference/featureset_functions/#groupby
    {name: 'Month', expression: 'Month_'},
    {name: 'Month Number', expression: 'Month_Num'}
  ],
    //statistics to return for each unique category
  [
    {name: 'HK by month', expression: 'HatcheryKept', statistic: 'SUM'},
    {name: 'HR by month', expression: 'HatcheryReleased', statistic: 'SUM'},
    {name: 'WR by month', expression: 'WildReleased', statistic: 'SUM'}
  ]);

return fsGp

 

 

And it returns what I wanted:

JanetBrewster1_0-1717790720780.png

 

However, when I use this same script when creating a new chart in the Dashboard, it doesn't work as there are no Profile variables to choose from (why is that?). I've found some other examples that use the Portal function, so tried this instead of what I have in line 3 above: 

 

var portalItem = Portal('https://**unspecified**.arcgis.com/');
var fs = FeatureSetByPortalItem(portalItem, '3879c57518f74a69bb3c52xxxxxxxxxx', 0, ["*"], false);

 

 

But I get "Test execution error: Unknown Error. Verify test data."

Maybe this is just a newbie mistake, but I can't figure out how to reference the data layer I want. I don't even know what the layer ID is -- I don't see anything in the Feature Layer details -- I'm just parroting from examples I've seen. Does it not work because my data and dashboard are not public yet?

Any insights would be greatly appreciated. Thank you!

1 Solution

Accepted Solutions
JanetBrewster1
New Contributor III

Ok, thanks to Esri tech help, I was able to figure out what I was doing wrong. 

I was using the ID of my Dashboard, when I should have used the ID of my hosted feature layer. And as for the layer number, that was spelled out in the REST Services Directory for the feature layer (the "View" link next to "URL" in the feature layer's Overview tab) -- I was referencing the wrong one.

So now it works and I can aggregate data from my large data layer and create a stacked chart.

Unfortunately, the stacked chart doesn't seem to like Actions...so still can't link it to the other charts, indicators, and selectors in the Dashboard.... Doh.

View solution in original post

0 Kudos
1 Reply
JanetBrewster1
New Contributor III

Ok, thanks to Esri tech help, I was able to figure out what I was doing wrong. 

I was using the ID of my Dashboard, when I should have used the ID of my hosted feature layer. And as for the layer number, that was spelled out in the REST Services Directory for the feature layer (the "View" link next to "URL" in the feature layer's Overview tab) -- I was referencing the wrong one.

So now it works and I can aggregate data from my large data layer and create a stacked chart.

Unfortunately, the stacked chart doesn't seem to like Actions...so still can't link it to the other charts, indicators, and selectors in the Dashboard.... Doh.

0 Kudos