▾
New York City short-term rental distribution count across different neighbourhood groups.
What is a bar chart?
Bar charts are used to summarize and compare categorical or temporal data, with values shown through the relative lengths of bars. The x-axis typically displays discrete categories or temporal intervals with each category or interval mapped to one or more bars, while the y-axis represents a numeric scale that determines the height of each bar.
Data configurations
This section covers a few data configuration examples for bar charts, each configured using the bar chart model. See the bar chart model reference for the full list of available properties and methods.
With category field
Bar chart with a category field renders one bar per unique category value.
- Set the
xAxisFieldproperty to"neighbourhood_group"to specify the category field.
29 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Bar chart with category field</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "a8fbe2753beb4cd4aeef4d47e5e32a7c", }, }); const chartElement = document.querySelector("arcgis-chart"); const barChartModel = await createModel({ layer: featureLayer, chartType: "barChart" }); barChartModel.xAxisField = "neighbourhood_group";11 collapsed lines
barChartModel.setAxisTitleText("Neighbourhood Group", 0); barChartModel.titleText = "NYC Short-Term Rental by Neighbourhood Group"; barChartModel.setAxisValueFormat(0, { type: "category", characterLimit: 20, }); chartElement.model = barChartModel; chartElement.actionMode = "none"; </script> </body></html>With numeric fields
Bar chart with a category field and numeric fields renders one bar per category, with the height of each bar determined by the specified aggregation of the numeric field.
- Set the
xAxisFieldproperty to"neighbourhood_group". - Set the
numericFieldsproperty to"price"to specify the numeric field. - Set the
aggregationTypeproperty to"avg"to calculate the average price per neighborhood group.
29 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Bar chart with numeric fields</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "a8fbe2753beb4cd4aeef4d47e5e32a7c", }, }); const chartElement = document.querySelector("arcgis-chart"); const barChartModel = await createModel({ layer: featureLayer, chartType: "barChart" }); barChartModel.xAxisField = "neighbourhood_group"; barChartModel.numericFields = "price"; barChartModel.aggregationType = "avg";12 collapsed lines
barChartModel.setAxisTitleText("Neighbourhood Group", 0); barChartModel.titleText = "NYC Short-Term Rental Average Price by Neighbourhood Group"; barChartModel.dataLabelsVisibility = true; barChartModel.setAxisValueFormat(0, { type: "category", characterLimit: 20, }); chartElement.model = barChartModel; chartElement.actionMode = "none"; </script> </body></html>With split by field
Bar chart with a category field and a split by field displays multiple related data series side by side within each category.
- Set the
xAxisFieldproperty to"neighbourhood_group". - Set the
splitByFieldproperty to"room_type"to divide each main category into grouped bars for subcategory comparison.
29 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Bar chart with split by field</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "a8fbe2753beb4cd4aeef4d47e5e32a7c", }, }); const chartElement = document.querySelector("arcgis-chart"); const barChartModel = await createModel({ layer: featureLayer, chartType: "barChart" }); barChartModel.xAxisField = "neighbourhood_group"; barChartModel.splitByField = "room_type";13 collapsed lines
barChartModel.setAxisTitleText("Neighbourhood Group", 0); barChartModel.titleText = "NYC Short-Term Rental Room Types by Neighbourhood Group"; barChartModel.legendTitleText = "Room type"; barChartModel.dataLabelsVisibility = true; barChartModel.setAxisValueFormat(0, { type: "category", characterLimit: 20, }); chartElement.model = barChartModel; chartElement.actionMode = "none"; </script> </body></html>With date field
Bar chart configured with a date field (temporal bar chart) as the category field can visualize data over time, allowing trends and patterns to be easily identified.
- Set the
xAxisFieldproperty to"last_review"(a date field). - Set the
binTemporalDataproperty totrueto enable temporal binning, which groups date values into time intervals for better visualization. - Set the
temporalBinningSizeproperty and thetemporalBinningUnitproperty to group the date values.
29 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Bar chart with date field</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "a8fbe2753beb4cd4aeef4d47e5e32a7c", }, }); const chartElement = document.querySelector("arcgis-chart"); const barChartModel = await createModel({ layer: featureLayer, chartType: "barChart" }); barChartModel.xAxisField = "last_review"; barChartModel.binTemporalData = true; barChartModel.temporalBinningUnit = "months"; barChartModel.temporalBinningSize = 6;8 collapsed lines
barChartModel.setAxisTitleText("Review Period", 0); barChartModel.titleText = "NYC Short-Term Rental Reviews by 6-Month Period"; barChartModel.dataLabelsVisibility = true; chartElement.model = barChartModel; chartElement.actionMode = "none"; </script> </body></html>Customization options
Stacked type
When a bar chart is configured with multiple numeric fields or a split by field, you can set the stackedType property to display the bars as stacked percentages.
sideBySide(default): Bars are displayed next to each other for each category, allowing for easy comparison of individual data series.stacked: Bars are displayed on top of each other for each category, showing the cumulative total and the relative contribution of each data series.stacked100: Bars are displayed on top of each other for each category, with each bar representing 100% of the total, emphasizing the relative contribution of each data series within the category.
| Stacked | 100% Stacked |
|---|---|
![]() | ![]() |

