Select to view content in your preferred language

Unable to generate chart in ArcGIS Online Pop Up

177
0
08-21-2024 08:56 PM
Labels (1)
JohnHughson
Occasional Contributor
Hello everyone.
 
I'm at a loss in regarding help documentation for structuring this. I need to generate a linechart within a pop up for an ArcGIS Online web map. I understand that this has to be done using an 'Arcade' element rather than plugging an expression straight into the charts function. 
 
My final script makes use of related records, but I believe my issues lies in the general structure of the expression. Therefore, I have a static expression below that I have been testing with to figure out what it is I'm doing incorrectly. 
 
Presently, it loads an empty chart, with no labels, titles, or values of any kind into the pop up. 
 
Does anybody know how to amend the below expression such that it will correctly generate a chart in an ArcGIS Online web map pop up?
 
 
 
// X-axis values (Years)
var years = [2018, 2019, 2020, 2021, 2022];

// Data series (Single line)
var series1 = [10, 15, 20, 25, 30]; // Static values for Series 1

// Prepare the chart values
var chartValues = [
    { year: 2018, value: 10 },
    { year: 2019, value: 15 },
    { year: 2020, value: 20 },
    { year: 2021, value: 25 },
    { year: 2022, value: 30 }
];

// Field names for the chart
var chartNames = ["year", "value"];

// Return the chart configuration
return {
    type: 'media',
    title: 'Sample Line Chart',
    description: 'Line chart showing sample data over years',
    attributes: {
        year: years,
        value: series1
    },
    mediaInfos: [{
        type: 'linechart', //linechart | barchart | piechart | columnchart
        altText: 'line chart showing sample data over years', //altText will be read by screen readers
        value: {
            fields: chartNames,  // choose what attributes to use in the chart
            data: chartValues,   // include the data for the chart
            xAxisField: 'year',
            yAxisField: 'value'
        }    
    }]
};
 
Hopefully this might serve as valuable information for others looking to use charts in their pop ups as well. 
0 Kudos
0 Replies