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 data, with values shown through the relative lengths of bars. The x-axis displays discrete categories (each 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 demonstrates how different data configurations can be used to create various types of bar charts, including category field, numeric fields, split by field, and date field configurations.

With category field

Bar chart with a category field renders one bar per unique category value.

The above 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.
Charts component
30 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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";
8 collapsed lines
barChartModel.setAxisTitleText("Neighbourhood Group", 0);
barChartModel.titleText = "NYC Short-Term Rental by Neighbourhood Group";
chartElement.model = barChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

With numeric fields

  • When only numeric fields are specified via the numericFields property, each field becomes a category and the bar height reflects its value.
  • With one category field specified via the xAxisField property and one numeric field specified via the numericFields property, the chart renders one bar per category showing that numeric value.
  • With one category field specified via the xAxisField property and multiple numeric fields specified via the numericFields property, the chart renders grouped bars per category (one bar per numeric field).

The above 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.
Charts component
30 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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";
9 collapsed lines
barChartModel.setAxisTitleText("Neighbourhood Group", 0);
barChartModel.titleText = "NYC Short-Term Rental Average Price by Neighbourhood Group";
barChartModel.dataLabelsVisibility = true;
chartElement.model = barChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

With split by field

A split by bar chart displays multiple related data series side by side within each category.

The above 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.
Charts component
30 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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";
10 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;
chartElement.model = barChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

With date field

A temporal bar chart visualizes data over time, allowing trends and patterns to be easily identified.

The above chart visualizes NYC short-term rental reviews, binned into 6-month intervals.

  1. Set the xAxisField property to "last_review", which is 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.
Charts component
30 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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";
chartElement.model = barChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

Customization options

Stacked bar chart

A stacked bar chart need to have multiple numeric fields or use a split by field to create the stacks. It can be helpful to visualize the contribution of each data series to the total within each category.

The above chart shows the distribution of short-term rentals in NYC by neighborhood group, each bar represents a stacked percentage distribution of room types within each neighborhood group.

  1. With a multiple numeric fields or split by field bar chart configured, set the stackedType property to "stacked100" to display the bars that sums up to 100%.
Charts component
32 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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";
barChartModel.stackedType = "stacked100";
10 collapsed lines
barChartModel.dataLabelsVisibility = true;
barChartModel.setAxisTitleText("Neighbourhood Group", 0);
barChartModel.legendTitleText = "Room type";
barChartModel.titleText = "NYC Short-Term Rental Room Types by Neighbourhood Group (Stacked)";
chartElement.model = barChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>