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 1 | Fed Source 2 | Local Source 1 | Local Source 2 | Local 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.
Solved! Go to Solution.
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
If you're using an existing dashboard, you'll see something like this dialog
In either case, click "New data expression" to add your Arcade code.
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}
}]
}
);
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?
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
If you're using an existing dashboard, you'll see something like this dialog
In either case, click "New data expression" to add your Arcade code.