Hi all,
I am trying to create a chart in the pop up of the map using arcade. I have a layer with a dataset that has a "year", a "units" field (number of housing units for that year), and a "town" field (which has corresponding geometry for the map). I would like the popup to create a chart when you click on the town that categorizes the units into years, so it will be a column chart with the x-axis as categories for "years" and the y-axis is the sum of the units for that year.
I am referencing this blog post to try to accomplish this: Part 2: Introducing Arcade pop-up content elements (esri.com)
This is my arcade script. When I run it in the window, it gives an error: Test execution error: Unknown Error. Verify test data. And then, obviously, no chart shows up in the popup.
This is my script so far (edited from the blog post linked above):
var x = GroupBy($layer, 'year', { name: 'total', expression: 'units', statistic: 'SUM' });
var sorted = OrderBy(x, 'count DSC')
var chartValues = {}
var chartNames = []
for(var f in sorted) {
	chartValues[f.year] = f.total
	Push(chartNames, f.year)
}
return {
    type: 'media',
    title : 'Crime by precinct',
    description : 'Chart showing total crime by crime category',
    attributes : chartValues,  // replace this dictionary with your own key-value pairs,
    mediaInfos: [{
        type : 'columnchart', //linechart | barchart | piechart | columnchart
        //title : '',
        //caption : '',
        altText : 'bar chart showing units by year', //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 
        }	  
      }]
}
Thanks for checking this out and let me know if anyone has any ideas of what I can try.
Solved! Go to Solution.
There are a couple of things going on.
Give this a try
var x = GroupBy($layer, 'Year', { name: 'total', expression: 'units', statistic: 'SUM' });
var sorted = OrderBy(x, 'total DESC')
var chartValues = {}
var chartNames = []
for(var f in sorted) {
	console(f.year)
	chartValues[`${f.year}`] = f.total
	Push(chartNames, f.year)
}
There are a couple of things going on.
Give this a try
var x = GroupBy($layer, 'Year', { name: 'total', expression: 'units', statistic: 'SUM' });
var sorted = OrderBy(x, 'total DESC')
var chartValues = {}
var chartNames = []
for(var f in sorted) {
	console(f.year)
	chartValues[`${f.year}`] = f.total
	Push(chartNames, f.year)
}