▾
In this tutorial, you will:
- Load and display a pre-configured web map
A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. stored in ArcGIS Online with the<arcgis-map>component. - Load and display multiple pre-configured charts from the web map
A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. stored in ArcGIS Online using the<arcgis-chart>component with thereference-element,map-layer-idandchart-indexattributes. - Add the
<arcgis-charts-action-bar>component that will allow more interaction actions with the chart. - Add the
<arcgis-selection-toolbar>component to enable selection on the map. - Explore interactive functionalities, such as filtering by extent of the map and synchronizing selections between the charts and the map.
Prerequisites
Steps
Create a new pen
- Go to CodePen to create a new pen for your application.
Add basic HTML
Define a basic HTML page.
- In CodePen > HTML, add HTML to create a basic page.
<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title></head><body></body></html>
Add styling
-
In the
<head>tag, add CSS to style the page layout for the map and chart components. It uses a grid layout to split the viewport into two columns and two rows, placing the map on the left and the charts on the right.6 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title><style>html,body {height: 100%;margin: 0;}body {display: grid;grid-template-columns: 50% 50%;grid-template-rows: 50% 50%;}arcgis-map {grid-row: span 2;}arcgis-chart {grid-column: 2;}</style>10 collapsed lines</head><body></body></html>
Add the ArcGIS Maps SDK for JavaScript script tag
-
In the
<head>, add the<script>tag for the JavaScript Maps SDK.6 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.2/"></script>10 collapsed lines</head><body></body></html>
Add map components
-
In the
<body>, add the<arcgis-map>component.- Set the
item-idattribute to the ID of the map you want to display. - Set the
idtomapto be used by the reference element later in the tutorial.
32 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title><style>html,body {height: 100%;margin: 0;}body {display: grid;grid-template-columns: 50% 50%;grid-template-rows: 50% 50%;}arcgis-map {grid-row: span 2;}arcgis-chart {grid-column: 2;}</style><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.2/"></script></head><body><arcgis-map item-id="f2481ef191924872be8897179f73d55c" id="map"></arcgis-map>16 collapsed lines<arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="0" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart><arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="1" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart></body></html> - Set the
-
Within the
<arcgis-map>component, add the<arcgis-selection-toolbar>component to enable selection tools for the map.32 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title><style>html,body {height: 100%;margin: 0;}body {display: grid;grid-template-columns: 50% 50%;grid-template-rows: 50% 50%;}arcgis-map {grid-row: span 2;}arcgis-chart {grid-column: 2;}</style><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.2/"></script></head><body><arcgis-map item-id="f2481ef191924872be8897179f73d55c" id="map"><arcgis-selection-toolbarslot="top-right"default-operation-type="add"visual-scale="s"></arcgis-selection-toolbar></arcgis-map>16 collapsed lines<arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="0" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart><arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="1" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart></body></html>
Add charts components
-
Below the map component, add the
<arcgis-chart>component.- Set the
reference-elementattribute tomap(theidof the map component). This links the chart to the map element. - Set the
map-layer-idattribute to the ID of the map layer you want to link the chart to. - Set the
chart-indexattribute to0to indicate that this is the first chart linked to the map layer. - Add the
sync-view-selectionattribute to enable synchronization of selection between the chart and the map.
43 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title><style>html,body {height: 100%;margin: 0;}body {display: grid;grid-template-columns: 50% 50%;grid-template-rows: 50% 50%;}arcgis-map {grid-row: span 2;}arcgis-chart {grid-column: 2;}</style><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.2/"></script></head><body><arcgis-map item-id="f2481ef191924872be8897179f73d55c" id="map"><arcgis-selection-toolbarslot="top-right"default-operation-type="add"visual-scale="s"></arcgis-selection-toolbar></arcgis-map><arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="0" sync-view-selection></arcgis-chart>9 collapsed lines<arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="1" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart></body></html> - Set the
-
Within the
<arcgis-chart>component, add the<arcgis-charts-action-bar>component and set the slot toaction-bar.The action bar provides built-in actions such as toggling legend visibility, rotation, filtering by selection, filtering by view extent, exporting as images or tables and more.
43 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title><style>html,body {height: 100%;margin: 0;}body {display: grid;grid-template-columns: 50% 50%;grid-template-rows: 50% 50%;}arcgis-map {grid-row: span 2;}arcgis-chart {grid-column: 2;}</style><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.2/"></script></head><body><arcgis-map item-id="f2481ef191924872be8897179f73d55c" id="map"><arcgis-selection-toolbarslot="top-right"default-operation-type="add"visual-scale="s"></arcgis-selection-toolbar></arcgis-map><arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="0" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart>9 collapsed lines<arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="1" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart></body></html> -
Lastly, repeat the first two steps to add the second chart to the page, specifying the appropriate
chart-indexfor the second chart.50 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Chart and map interactions</title><style>html,body {height: 100%;margin: 0;}body {display: grid;grid-template-columns: 50% 50%;grid-template-rows: 50% 50%;}arcgis-map {grid-row: span 2;}arcgis-chart {grid-column: 2;}</style><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.2/"></script></head><body><arcgis-map item-id="f2481ef191924872be8897179f73d55c" id="map"><arcgis-selection-toolbarslot="top-right"default-operation-type="add"visual-scale="s"></arcgis-selection-toolbar></arcgis-map><arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="0" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart><arcgis-chart reference-element="map" map-layer-id="194f7ed3447-layer-50" chart-index="1" sync-view-selection><arcgis-charts-action-bar slot="action-bar"></arcgis-charts-action-bar></arcgis-chart>4 collapsed lines</body></html>
Run the app
In CodePen, explore how selections stay in sync across the map and charts, and how the map’s extent filters chart data.
- Select a column in either chart to select the corresponding features on the map and in the other chart.
- Use the map’s selection toolbar to select features and update both charts.
- Choose
Filter by view extentin a chart’s action bar to filter its data to the current map extent.