I am trying to create a dashboard gauge to show percentage of time passed in a season. So, if the season runs from 1 July to 30 September, then on 23 July, the gauge should read 25%.
I want the FeatureSet to show the percentage in the 'DayPercentage' field for the gauge.
My Arcade code to do so is as follows:
var ThisYear = Number(Year(Now()));
//var ThisMonth = Month(Now());
//var ThisDay = Day(Now())
var startDate = Number(Date(ThisYear,7,1));
var endDate = Number(Date(ThisYear,9,30));
var currentDate = Number(Date(ThisYear, 7, 25));
var Season = Number(DateDiff(endDate,startDate))
var SeasonSoFar = Number(DateDiff(currentDate,startDate))
var SeasonPerc = Number((SeasonSoFar/Season)*100);
var features = [];
Push(features, SeasonPerc)
var PercDict = {
'fields': [
{'name':'DayPercentage','type':'esriFieldTypeInteger'}
],
'features': features
};
var features2 = FeatureSet(PercDict);
return features2
This returns a null dataset. I've tried formatting the Dictionary differently, formatting the FeatureSet differently, using Push to get the data through in different places and formats, and I'm stuck. What am I doing wrong?
There were a couple of things that needed changing.
var ThisYear = Year(Now());
//var ThisMonth = Month(Now());
//var ThisDay = Day(Now())
var startDate = Date(ThisYear, 6, 1);
var endDate = Date(ThisYear, 8, 30);
var currentDate = Date(ThisYear, 6, 25);
var Season = DateDiff(endDate, startDate);
var SeasonSoFar = DateDiff(currentDate, startDate);
var SeasonPerc = Round(Number(SeasonSoFar / Season * 100));
var features = [];
Push(features, { attributes: { DayPercentage: SeasonPerc } });
var PercDict = {
fields: [{ name: "DayPercentage", type: "esriFieldTypeInteger" }],
features: features
};
var features2 = FeatureSet(PercDict);
return features2;
Thank you so much!
Many of those changes were things I had actually done correctly the first time but had changed in all my attempts to fix this. The push with attributes was the missing piece.
Glad to help. Please check the "Accept as Solution" box to help others searching on this problem