<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic popup chart from related table in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/popup-chart-from-related-table/m-p/1632180#M65525</link>
    <description>&lt;P&gt;I am trying to make a line chart in the popup from a related table of inspections. The Arcade expression spits out data, but the chart does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how to get the chart to work?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;AJ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;// Get the related table
var table = FeatureSetByName($map, "Monitoring");

// Feature's matching ID (Name)
var myID = $feature["Name"];

// Array to hold features for chart
var features = [];

// Loop through table rows
for (var row in table) {
    // Only include rows matching the current feature
    if (row["CulvertID"] != myID) {
        continue;
    }

    var d = row["Date"];
    var h = row["AverageHeight"];

    // Skip invalid or empty data
    if (IsEmpty(d) || IsEmpty(h)) {
        continue;
    }

    // Push attributes as needed for chart
    Push(features, {
        attributes: {
            Date: d,
            AverageHeight: h
        }
    });
}

// Return data for popup chart
return {
    fields: [
        { name: "Date", type: "esriFieldTypeDate" },
        { name: "AverageHeight", type: "esriFieldTypeDouble" }
    ],
    geometryType: "",
    features: features
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;dictionary
features: array(5)
0: dictionary
attributes: dictionary
AverageHeight: 34.25
Date: Mar 5, 2025, 8:47:34 AM Eastern Standard Time
1: dictionary
attributes: dictionary
AverageHeight: 34.83
Date: Mar 12, 2025, 1:39:34 PM Eastern Daylight Time
2: dictionary
attributes: dictionary
AverageHeight: 34.17
Date: Mar 19, 2025, 2:59:09 PM Eastern Daylight Time
3: dictionary
attributes: dictionary
AverageHeight: 0
Date: Mar 27, 2025, 2:15:07 PM Eastern Daylight Time
4: dictionary
attributes: dictionary
AverageHeight: 0
Date: Jun 18, 2025, 8:52:35 AM Eastern Daylight Time
fields: array(2)
0: dictionary
name: "Date"
type: "esriFieldTypeDate"
1: dictionary
name: "AverageHeight"
type: "esriFieldTypeDouble"
geometryType: ""&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Jul 2025 19:33:32 GMT</pubDate>
    <dc:creator>AJM</dc:creator>
    <dc:date>2025-07-10T19:33:32Z</dc:date>
    <item>
      <title>popup chart from related table</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-chart-from-related-table/m-p/1632180#M65525</link>
      <description>&lt;P&gt;I am trying to make a line chart in the popup from a related table of inspections. The Arcade expression spits out data, but the chart does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how to get the chart to work?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;AJ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;// Get the related table
var table = FeatureSetByName($map, "Monitoring");

// Feature's matching ID (Name)
var myID = $feature["Name"];

// Array to hold features for chart
var features = [];

// Loop through table rows
for (var row in table) {
    // Only include rows matching the current feature
    if (row["CulvertID"] != myID) {
        continue;
    }

    var d = row["Date"];
    var h = row["AverageHeight"];

    // Skip invalid or empty data
    if (IsEmpty(d) || IsEmpty(h)) {
        continue;
    }

    // Push attributes as needed for chart
    Push(features, {
        attributes: {
            Date: d,
            AverageHeight: h
        }
    });
}

// Return data for popup chart
return {
    fields: [
        { name: "Date", type: "esriFieldTypeDate" },
        { name: "AverageHeight", type: "esriFieldTypeDouble" }
    ],
    geometryType: "",
    features: features
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;dictionary
features: array(5)
0: dictionary
attributes: dictionary
AverageHeight: 34.25
Date: Mar 5, 2025, 8:47:34 AM Eastern Standard Time
1: dictionary
attributes: dictionary
AverageHeight: 34.83
Date: Mar 12, 2025, 1:39:34 PM Eastern Daylight Time
2: dictionary
attributes: dictionary
AverageHeight: 34.17
Date: Mar 19, 2025, 2:59:09 PM Eastern Daylight Time
3: dictionary
attributes: dictionary
AverageHeight: 0
Date: Mar 27, 2025, 2:15:07 PM Eastern Daylight Time
4: dictionary
attributes: dictionary
AverageHeight: 0
Date: Jun 18, 2025, 8:52:35 AM Eastern Daylight Time
fields: array(2)
0: dictionary
name: "Date"
type: "esriFieldTypeDate"
1: dictionary
name: "AverageHeight"
type: "esriFieldTypeDouble"
geometryType: ""&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jul 2025 19:33:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-chart-from-related-table/m-p/1632180#M65525</guid>
      <dc:creator>AJM</dc:creator>
      <dc:date>2025-07-10T19:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: popup chart from related table</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-chart-from-related-table/m-p/1632376#M65534</link>
      <description>&lt;P&gt;AJ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is code I have used to pull from historic hydrant flow tests (in a related table) to display flow and pressure data as a bar chart.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BlairMcclenathan_0-1752237626032.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/136371i7EBF976328E2153D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BlairMcclenathan_0-1752237626032.png" alt="BlairMcclenathan_0-1752237626032.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;       var MAX_TESTS   = 10;
    
    /* ───────────────────── 1. Fetch flow-test rows ───────────────────── */
    
    var PORTAL      = Portal("https://arcgis.yourportal.com/portal");
    var ITEM_ID     = "";
    var FLOW_LAYER  = ;                        // table-id for flow tests
    var FK_FIELD    = "FACILITYID";             // foreign-key in table 6
    var fields      = ["flowrate","residualpressure","staticpressure",
                       "testingdate", FK_FIELD];
    
    var flowTests   = FeatureSetByPortalItem(
                        PORTAL, ITEM_ID, FLOW_LAYER,
                        fields, false);
    
    /* WHERE FACILITYID = '&amp;lt;current hydrant’s FACILITYID&amp;gt;' */
    var facID = Trim(Text($feature[FK_FIELD]));
    if (IsEmpty(facID)) { return; } 
    var where = FK_FIELD + " = '" + facID + "'";
    var tests = Filter(flowTests, where);
    
    if (Count(tests) == 0) { return; }          // no matching tests
    
    /* ───────────────────── 2. Build per-metric lists ─────────────────── */
    
    var ordered   = OrderBy(tests, "testingdate DESC");   // newest → oldest
    var attrs     = {};
    var flowFlds  = [];
    var resFlds   = [];
    var staFlds   = [];
    
    var used      = {};
    var rowsAdded = 0;
    
    for (var rec in ordered) {
      if (rowsAdded == MAX_TESTS) { break; }
      if (IsEmpty(rec.testingdate)) { continue; }
    
      var base = Text(rec.testingdate, "YYYY-MM-DD");
      var lbl  = base;
      var dup  = 2;
      while (HasKey(used, lbl)) {
        lbl = base + " (" + dup + ")";
        dup += 1;
      }
      used[lbl] = true;
    
      if (!IsEmpty(rec.flowrate)) {
        var k = lbl + "_flow";
        attrs[k] = rec.flowrate;
        Push(flowFlds, k);
      }
      if (!IsEmpty(rec.residualpressure)) {
        var k = lbl + "_residual";
        attrs[k] = rec.residualpressure;
        Push(resFlds, k);
      }
      if (!IsEmpty(rec.staticpressure)) {
        var k = lbl + "_static";
        attrs[k] = rec.staticpressure;
        Push(staFlds, k);
      }
      rowsAdded += 1;
    }
    
    /* oldest → newest for chronological bars */
    flowFlds = Reverse(flowFlds);
    resFlds  = Reverse(resFlds);
    staFlds  = Reverse(staFlds);
    
    /* ─────────────── 3. Linear-regression trend caption ─────────────── */
    
    function captionLR(flds){
      var n = Count(flds);
      if (n &amp;lt; 2) { return " (trend unavailable)"; }
    
      var sumX  = 0;
      var sumY  = 0;
      var sumX2 = 0;
      var sumXY = 0;
    
      for (var i = 0; i &amp;lt; n; i++) {
        var y = attrs[flds[i]];
        if (IsEmpty(y)) { return " (trend unavailable)"; }
    
        sumX  += i;
        sumY  += y;
        sumX2 += i * i;
        sumXY += i * y;
      }
    
      var denom = n * sumX2 - sumX * sumX;
      if (denom == 0) { return " (trend unavailable)"; }
    
      var slope = (n * sumXY - sumX * sumY) / denom;   // Δy per test
      var arrow = IIf(slope &amp;gt; 0, "▲",
                  IIf(slope &amp;lt; 0, "▼", "►"));
      var txt   = Text(Abs(slope), "#,###.0");
    
      return arrow + " " + txt;
    }
    
    var flowCap = captionLR(flowFlds);
    var resCap  = captionLR(resFlds);
    var staCap  = captionLR(staFlds);
    
    /* ─────────────────── 4. Assemble the charts ─────────────────────── */
    
    var colors = [
      [48,67,77,255],[8,97,107,255],[0,118,132,255],[0,140,153,255],
      [96,124,151,255],[39,153,137,255],[115,140,167,255],[137,158,179,255],
      [161,178,196,255],[188,206,221,255]
    ];
    
    var charts = [];
    
    if (Count(flowFlds) &amp;gt; 0) {
      Push(charts,{
        type:'columnchart',
        title:'Flow Rate (GPM)',
        caption:flowCap,
        value:{fields:flowFlds,colors:colors}
      });
    }
    if (Count(resFlds) &amp;gt; 0) {
      Push(charts,{
        type:'columnchart',
        title:'Residual Pressure (PSI)',
        caption:resCap,
        value:{fields:resFlds,colors:colors}
      });
    }
    if (Count(staFlds) &amp;gt; 0) {
      Push(charts,{
        type:'columnchart',
        title:'Static Pressure (PSI)',
        caption:staCap,
        value:{fields:staFlds,colors:colors}
      });
    }
    
    if (Count(charts) == 0) { return; }
    
    /* ───────────────────── 5. Return Chart ──────────────────── */
    
    return {
      type      : 'media',
      attributes: attrs,
      mediaInfos: charts
    };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2025 12:41:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-chart-from-related-table/m-p/1632376#M65534</guid>
      <dc:creator>BlairMcclenathan</dc:creator>
      <dc:date>2025-07-11T12:41:00Z</dc:date>
    </item>
  </channel>
</rss>

