Help, Need to show a related table graph in a popup using Arcade

I’m working on a project that requires a chart in a popup based on records from a related table. When any feature is identified, the popup needs to display a chart which shows the dates the feature was mowed on the X axis and the number of mowing minutes on the Y axis.

The default popup will show a chart for each related record, but I am at a loss as to how the records can be grouped into a single chart. The chart will also only appear in the secondary popup when the related record button is clicked in the feature’s popup. I would like the chart to appear in the feature’s popup, rather than the table popup. This will allow the user to interact with 1 popup card rather than flipping through multiple related cards, while consolidating the information into a chart for comparison among mowing events.

The feature layer has a configuration with a related table with a one-to-many relate. The origin table contains a primary key and address. The related table contains the foreign key, dates, number of mowing minutes. I’m sure there is a solution using Arcade, but I am unable to determine how to bring related recorded into the popup of the primary feature layer.

Here is an example of the origin table record and 3 related table records.

Origin Table
OBJECTID = 1
PRIMARYKEY = A0001
ADDRESS = 123 Any Street

Related Table
OBJECTID = 12
FOREIGNKEY = A0001
MOWDATE = 05/01/2025
MOWTIME = 23

OBJECTID = 13
FOREIGNKEY = A0001
MOWDATE = 05/15/2025
MOWTIME = 31

OBJECTID = 14
FOREIGNKEY = A0001
MOWDATE = 05/30/2025
MOWTIME = 27

The resulting chart needs to resemble this image.

Thank you for any assistance.
Adam

Hey Adam!

Try something like this as an Arcade popup element:

// get related records
var rel = OrderBy(FeatureSetByRelationshipName(
  $feature,
  'fse_inspections',
  ['inspection_date', 'duration'],
  false
), 'inspection_date ASC')

// placeholders for values
var attributes = {}
var fields = []

/* loop through records
for each, create an attribute with the category being the date as a string
the value being the duration itself.
push the attribute name into the fields array, too */

for (var r in rel) {
  var dt = Text(r['inspection_date'], 'YYYY-MM-DD')
  attributes[dt] = r['duration']
  Push(fields, dt)
}

return {
    type: 'media',
    attributes,
    mediaInfos: [{
        type : 'barchart',
        title : 'Duration per Inspection',
        value : { fields }
      }]
  }

Just swap in your field and relationship names as needed, but it appears to work on a layer of mine over here.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.