Arcade expression for pop-up chart to display average rainfall 30 days prior to a defect

416
0
06-02-2023 07:00 AM
Labels (1)
cat206
by
Occasional Contributor

Hi, I'm wondering if any Arcade experts can help me please? Using the below expression, I am able to list out the average rainfall in mm prior to a defect report date.

 

 

 

 

var weather = FeatureSetByName($map, "Weather Stations", ["*"], false)
 
var station = $feature.Closest_WeatherStation
var defectdate = $feature.Reported_Date___Time
var startDate = DateAdd(defectdate, -30, "days");
var endDate = DateAdd(defectdate, -1, "days");
var query = "Station = @station AND Date_Field >= @startDate AND Date_Field <= @endDate "
var filtered_weather = Filter(weather, query)
 
var return_lines = [

Count(filtered_weather) + " days forecast",

]

for(var d in filtered_weather) {

Push(return_lines, "Total Rainfall " + d.Daily_Total_Rainfall__0900_0900 + " mm")
}
return Concatenate(return_lines, Textformatting.NewLine)

 

 

 

 

However, rather than a list, I would like to display my results in a bar chart, displaying the date on the x axis and the average rainfall for each date up to 30 days before the defect date on the y axis. Is anyone able to help with this please?

I have tried this following the page Part 2: Introducing Arcade Pop-up Content Elements (esri.com) and come up with the below:

 

 

 

 

var weather = FeatureSetByName($map, "Weather Stations", ["*"], false)
 
var station = $feature.Closest_WeatherStation
var defectdate = $feature.Reported_Date___Time
var startDate = DateAdd(defectdate, -30, "days");
var endDate = DateAdd(defectdate, -1, "days");
var query = "Station = @station AND Date_Field >= @startDate AND Date_Field <= @endDate "
var filtered_weather = Filter(weather, query)
 
var return_lines = Average(filtered_weather)

var rainfall = groupBy(return_lines, 'Daily_Total_Rainfall__0900_0900',
                {name:'average', expression:'Daily_Total_Rainfall__0900_0900' , statistic:'AVERAGE'})

var chartValues = {}
var chartNames = []
for (var f in rainfall) {
        chartValues[f.Daily_Total_Rainfall__0900_0900] = f.average
        Push(chartNames, f.Date_Field)
    }

return {
    type: 'media',
    title : 'Rainfall by Date',
    description : 'Chart showing total rainfall 30 days prior to defect report date',
    attributes : chartValues,  // replace this dictionary with your own key-value pairs,
    mediaInfos: [{
        type : 'columnchart', //linechart | barchart | piechart | columnchart
        //title : '',
        //caption : '',
        altText : 'bar chart showing average rainfall by date', //altText will be read by screen readers
        value : {
          fields: chartNames,  // choose what attributes to use in the chart
          //normalizeField : '',  // the name of the attribute to normalize by or value 
        }	  
      }]
  }

 

 

 

 

 

 

 

0 Kudos
0 Replies