CodePen
Sandbox Download

Proportion of college undergraduates in different regions, with each slice representing a region and the size of the slice corresponding to the number of undergraduates in that region.

What is a pie chart?

Pie charts group data into slices to visualize part-to-whole relationships, the size of the slices correspond to the proportion of each category to the whole.

Data configurations

This section covers a few data configuration examples for pie charts, each configured using the pie chart model. See the pie chart model reference for the full list of available properties and methods.

With category field

Pie chart with a category field will display the count of features for each category. A category field must be a string or integer.

CodePen
Sandbox Download
This chart visualizes the proportion of college undergraduates in different regions. Each slice represents a region, with the size of the slice corresponding to the number of undergraduates in that region.
  1. Set the category property to "Region" to specify the category field.
With category field
28 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Pie 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: "8871626e970a4f3e9d6113ec63a92f2f",
},
});
const chartElement = document.querySelector("arcgis-chart");
const pieChartModel = await createModel({ layer: featureLayer, chartType: "pieChart" });
pieChartModel.category = "Region";
10 collapsed lines
pieChartModel.labelCharacterLimit = 20;
pieChartModel.dataLabelsVisibility = true;
pieChartModel.alignDataLabels = true;
pieChartModel.optimizeDataLabelsOverlapping = true;
pieChartModel.titleText = "Percentage of College Undergraduates by Region";
chartElement.model = pieChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

With numeric fields

Pie chart with only numeric fields will display each numeric field as its own slice, with values aggregated using the sum.

CodePen
Sandbox Download
This chart visualizes the population by age groups in the United States. Each slice represents an age group, with the size of the slice corresponding to the population in that age group.
  1. Set the numericFields property to specify the numeric fields.
With numeric fields
29 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Pie 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: "a8dd07c93e654c76b68951795a20a295",
},
});
const chartElement = document.querySelector("arcgis-chart");
const pieChartModel = await createModel({ layer: featureLayer, chartType: "pieChart" });
pieChartModel.numericFields = [
"AGE_UNDER5",
"AGE_5_17",
"AGE_18_21",
"AGE_22_29",
"AGE_30_39",
"AGE_40_49",
"AGE_50_64",
"AGE_65_UP",
];
9 collapsed lines
pieChartModel.titleText = "Population by Age Groups in the United States";
pieChartModel.dataLabelsVisibility = true;
pieChartModel.legendTitleText = "Age Group";
pieChartModel.legendPosition = "left";
chartElement.model = pieChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

With category and numeric fields

When both category and numeric fields are specified, the slices are aggregated by sum: the numeric field is summed for each unique value, and those totals are used to calculate each slice’s proportion.

CodePen
Sandbox Download
This chart visualizes the proportion of college undergraduates in different regions. Each slice represents a region, with the size of the slice corresponding to the number of undergraduates in that region.
  1. Set the category property to "Region" to specify the category field.
  2. Set the numericFields property to ["Undergrads"] to specify the numeric field to be aggregated for slice size.
With category and numeric fields
28 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Pie Chart with Category and 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: "8871626e970a4f3e9d6113ec63a92f2f",
},
});
const chartElement = document.querySelector("arcgis-chart");
const pieChartModel = await createModel({ layer: featureLayer, chartType: "pieChart" });
pieChartModel.category = "Region";
pieChartModel.numericFields = ["Undergrads"];
12 collapsed lines
pieChartModel.labelCharacterLimit = 20;
pieChartModel.dataLabelsVisibility = true;
pieChartModel.alignDataLabels = true;
pieChartModel.optimizeDataLabelsOverlapping = true;
pieChartModel.titleText = "Sum of College Undergraduates by Region";
pieChartModel.legendTitleText = "Region";
pieChartModel.legendPosition = "right";
chartElement.model = pieChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

Customization options

Start and end angles

Pie charts can be customized to display a full circle, half circle, or any other arc by adjusting the start and end angles from the startAngle and endAngle properties of the pie chart model.

The angles are specified in degrees, with 0 degrees pointing to the right (3 o’clock position) and increasing counterclockwise.

Default (full circle)startAngle: -200
endAngle: 20
startAngle: -180
endAngle: -90
startAngle: 0
endAngle: 180
Default start and end anglesStart angle -200, end angle 20Start angle -180, end angle -90Start angle 0, end angle 180

Inner radius

The inner radius of a pie chart can be adjusted using the innerRadius property of the pie chart model. This property controls the size of the inner circle, allowing you to create a donut chart by setting it to a value greater than 0, which can improve readability by providing more empty space in the center of the chart.

innerRadius: 10innerRadius: 50innerRadius: 80
Inner radius 10Inner radius 50Inner radius 80

Display options for data labels, tooltips, and legend items

Pie chart data labels, tooltips, and legend items can be customized to display each slice’s category, numeric value, and percentage.

By default,

Data labelsTooltipsLegend items
Data labelsTooltipsLegend items

Slice grouping

When a pie chart contains too many slices with small proportions, it might be difficult to read and interpret. In such cases, the smaller slices can be grouped into an “Other” category to improve readability.

CodePen
Sandbox Download
This chart visualizes the proportion of college undergraduates in different regions with smaller slices grouped into an "Other" category.
  1. Set the sliceGrouping property to customize the grouping slice.
  2. Set the percentageThreshold property to 12, which means any slice with a proportion smaller than 12% will be grouped into the “Other” category.
  3. Set the label property to "Less than 12%" to specify the name of the grouping slice. The legend item will be updated to reflect this label.
  4. Set the fillSymbol property to customize the fill symbol of the grouping slice. The legend item will be updated to reflect this symbol.
Slice grouping
30 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Pie Chart with Category and Numeric Fields with Grouping</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: "8871626e970a4f3e9d6113ec63a92f2f",
},
});
const chartElement = document.querySelector("arcgis-chart");
const pieChartModel = await createModel({ layer: featureLayer, chartType: "pieChart" });
pieChartModel.category = "Region";
pieChartModel.numericFields = ["Undergrads"];
pieChartModel.sliceGrouping = {
percentageThreshold: 12,
label: "Less than 12%",
fillSymbol: {
type: "esriSFS",
style: "esriSFSCross",
color: [255, 0, 255, 255],
outline: {
type: "esriSLS",
style: "esriSLSDot",
color: [0, 0, 0, 255],
width: 2,
},
},
};
12 collapsed lines
pieChartModel.labelCharacterLimit = 20;
pieChartModel.dataLabelsVisibility = true;
pieChartModel.alignDataLabels = true;
pieChartModel.optimizeDataLabelsOverlapping = true;
pieChartModel.titleText = "Sum of College Undergraduates by Region";
pieChartModel.legendTitleText = "Region";
pieChartModel.legendPosition = "right";
chartElement.model = pieChartModel;
chartElement.actionMode = "none";
</script>
</body>
</html>