CodePen
Sandbox Download

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.

CodePen
Sandbox Download
This chart visualizes the distribution of short-term rentals in NYC by neighborhood group, with each bar representing a neighborhood group category. The height of each bar reflects the count of rentals in that neighborhood group.
  1. Set the xAxisField property to "neighbourhood_group" to specify the category field.
Bar chart with category field example
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.

CodePen
Sandbox Download
This chart visualizes the average price of short-term rentals in NYC by neighborhood group.
  1. Set the xAxisField property to "neighbourhood_group".
  2. Set the numericFields property to "price" to specify the numeric field.
  3. Set the aggregationType property to "avg" to calculate the average price per neighborhood group.
Bar chart with numeric fields example
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.

CodePen
Sandbox Download
This chart visualizes the distribution of short-term rentals in NYC by neighborhood group, with each bar representing a neighborhood group category. The bars are split by room type, showing the count of each room type within each neighborhood group.
  1. Set the xAxisField property to "neighbourhood_group".
  2. Set the splitByField property to "room_type" to divide each main category into grouped bars for subcategory comparison.
Bar chart with split by field example
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.

CodePen
Sandbox Download
This chart visualizes the distribution of short-term rentals in NYC over time, with each bar representing a 6 month interval.
  1. Set the xAxisField property to "last_review"(a date field).
  2. Set the binTemporalData property to true to enable temporal binning, which groups date values into time intervals for better visualization.
  3. Set the temporalBinningSize property and the temporalBinningUnit property to group the date values.
Bar chart with date field example
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.
Stacked100% Stacked
Stacked100% Stacked