Use Arcade Expression to get the values of a related table to use later in a Chart within Pop-ups

18577
11
Jump to solution
06-22-2020 04:42 PM
AndresEcheverri
Regular Contributor

Hi All

I was wondering if someone could help me with this. I am trying to use a similar approach that have been suggested by Xander Bakker to use the‌ Filter function to get an array to use later in a chart. I have a hosted Feature Layer (Points) with the location of some wells. And I have an additional Table which has the "well" field (string field) in common with the hosted feature layer. From this table I was looking to pull out a couple of fields (oil production and date) to produce a Chart and add this chart to the Pop-up. The code in Arcade that I have is this one (from one previous post):

// first read out the well field of the Well layer
var well_name = $feature.well;
// access the table Monthly Production 
var tbl = FeatureSetByName($map,"FL_SA_PEPS_DATA - MonthlyProduction");
// create a sql expression to query on well
var sql = "well = '" + well_name + "'";
// filter the table using the sql expression
var related_data = Filter(tbl, sql);
// count the resulting records
var cnt = Count(related_data);

// initiate a variable to hold the result
var result = "Related records: " + cnt;;

// check if there are related records found for the current ID
if (cnt > 0) {
    // loop through related records
    for (var row in related_data) {
        // read some data and create the line you want
        
        //add the line to the result
       result += TextFormatting.NewLine + row.oil__m3_;
    }
}


// return the result
return result;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

With that code, I am able to get the list of dates or oil production and display those in the pop-up as text. Is it possible to use this as an array or sort of field to use them for the chart creation?. I can't see the result as an input for the chart.  I tried with this variant from other post: 

// initiate a variable to hold the result
var result = 0;

// check if there are related records found for the current ID
if (cnt > 0) {
    // loop through related records
    for (var row in related_data) {
       //add the line to the result
       result += row.oil__m3_;
    }
}

In this case, I got a single number, which then I can see as an input to create the chart, but is only a single number and not an array or table. Not sure what approach should I do?. Is something possible to do?. I am working in Portal for ArcGIS  10.7. Any help would be much appreciated.

Thanks,

Andres

0 Kudos
11 Replies
CapeCodCommission
Emerging Contributor

Hi there, this is very helpful stuff. However, I am getting a blank chart as well.

My expression returns proper chartValues and chartNames but the chart is blank besides the title and description. 

I am wondering if you have any ideas? I feel like I am so close....

0 Kudos
CapeCodCommission
Emerging Contributor

Hi, for the future soul:

I got this to work. Essentially, an empty chart is one's Arcade expression is working but one is passing values to the chart it cannot use.

My example was using this:

for (var f in SortedResults) {
        chartValues[Text(f.BeginDate, 'YYYY')] = (SUM(f.Direction1RawWeekDayAverage, f.Direction2RawWeekDayAverage))
        Push(chartNames, (Year(f.BeginDate)))
    }

For me to get it to work, the first chartValues in the dictionary had to be Text. But I think because I was doing some math (SUM), the second chartValues in the dictionary had to a number. Text did not work.

Lastly, I had to use the date function Year, to get my chartNames to match my first chartValues. Text did not work.

Long story short: monkey around with the data types of your data to make the chart happy.

0 Kudos