Select to view content in your preferred language

Arcade statement directly in a dashboard?

61
4
Jump to solution
Thursday
Labels (1)
AmyRoust
Frequent Contributor

Is it possible to use Arcade inside an element on a dashboard? Or do I need to do the math in a web map and then refer to that field?

Here's what I'm trying to do (fake data for illustration):

Fed Source 1Fed Source 2Local Source 1Local Source 2Local Source 3
$999$999$444$444$444
$523$231$123$153$9751
$6237$94086$0$0$0
$0$0$992$1000$904

 

I want to create a donut chart that shows the percentage of federal funding versus local funding. My thought was that I could write an Arcade statement to add up Fed Source 1 and Fed Source 2 and call it FED, then write an Arcade statement to add up Local Source 1, Local Source 2, and Local Source 3 and call it LOCAL. I'm not seeing any place inside Dashboards where I can do statements like this, but I thought I'd ask to be certain.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

When you add an element to the dashboard, you have the choice of selecting a layer or a data expression. If it's an empty dashboard, you'll be present with this dialog

Snag_1a531ce.png

If you're using an existing dashboard, you'll see something like this dialog 

Snag_1a7a232.png

In either case, click "New data expression" to add your Arcade code.

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

You can do this with a data expression that would supply a FeatureSet to the chart. In the data expression, you would fetch the data set and use the Sum function expression for each field and add them up. Then you would put those values into a new FeatureSet (since a data expression needs to return a FeatureSet).

That would look something like this

// Fetches features from a public portal item
var fs = FeatureSetByPortalItem(
  Portal("yourPortal"),
  "yourItem",
  0,
  ["Fed1", "Fed2", "Local1", "Local2", "Local3"],
  false
);

var fed = Round(Sum(fs, "Fed1") + Sum(fs, "Fed2"), 2);
var local = Round(Sum(fs, "Local1") + Sum(fs, "Local2") + Sum(fs, "Local3"), 2);

return FeatureSet(
  {
    fields: [
      { name: "Federal", type: "esriFieldTypeSingle" },
      { name: "Local", type: "esriFieldTypeSingle" }
    ],
    features: [{
      attributes: {Federal: fed, Local: local}
    }]
  }
);

 

0 Kudos
AmyRoust
Frequent Contributor

Thanks, @KenBuja. The code isn't my issue - my question is: is there a place in ArcGIS Dashboards where I can write code? Or do I have to write it in a web map and then use the web map in the dashboard?

0 Kudos
KenBuja
MVP Esteemed Contributor

When you add an element to the dashboard, you have the choice of selecting a layer or a data expression. If it's an empty dashboard, you'll be present with this dialog

Snag_1a531ce.png

If you're using an existing dashboard, you'll see something like this dialog 

Snag_1a7a232.png

In either case, click "New data expression" to add your Arcade code.

AmyRoust
Frequent Contributor

Bingo! Thank you @KenBuja ! I was speeding through that step so fast that I missed it completely.

0 Kudos