PieChartRenderer

AMD: require(["esri/renderers/PieChartRenderer"], (PieChartRenderer) => { /* code goes here */ });
ESM: import PieChartRenderer from "@arcgis/core/renderers/PieChartRenderer";
Class: esri/renderers/PieChartRenderer
Inheritance: PieChartRenderer Renderer Accessor
Since: ArcGIS API for JavaScript 4.24

PieChartRenderer allows you to create a pie chart for each feature in the layer. The value and color of each pie slice is specified in the attributes property. You can vary the size of each pie based on data with any other field value or Arcade expression using visualVariables.

pie chart renderer

Known Limitations

See also
Example
layer.renderer = {
  type: "pie-chart",  // autocasts as new PieChartRenderer()
  attributes: [{
    field: "ELEMENTARY_SCHOOL",
    label: "Elementary School",
    color: "red"
  }, {
    field: "MIDDLE_SCHOOL",
    label: "Middle School",
    color: "blue"
  }, {
    field: "HIGH_SCHOOL",
    label: "High School",
    color: "orange"
  }, {
    valueExpression: "$feature.ASSOCIATES_DEGREE + $feature.BACHELOR_DEGREE + $feature.MASTER_DEGREE + $feature.DOCTORATE_DEGREE",
    valueExpressionTitle: "People who completed university",
    label: "University"
    color: "green"
  }]
};

Constructors

new PieChartRenderer(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class
AttributeColorInfo[]

Defines the variable(s) to include in the pie charts.

more details
PieChartRenderer
AuthoringInfo

Authoring metadata only included in renderers generated from one of the Smart Mapping creator methods, such as sizeRendererCreator.createContinuousRenderer() or colorRendererCreator.createContinuousRenderer().

more details
Renderer
SimpleFillSymbol

The symbol used to render polygons behind the pie symbols.

more details
PieChartRenderer
String

The name of the class.

more details
Accessor
Color

The color used to visualize features whose attributes all have null or empty values.

more details
PieChartRenderer
String

Describes the defaultColor in the Legend.

more details
PieChartRenderer
Number

Use this property to create a donut chart.

more details
PieChartRenderer
Object

An object providing options for describing the renderer in the Legend.

more details
PieChartRenderer
Object

Defines the rules for how to aggregate small categories to a generic "others" category.

more details
PieChartRenderer
SimpleLineSymbol

Defines the outline of the pie chart.

more details
PieChartRenderer
Number

Defines the size of each pie chart in points.

more details
PieChartRenderer
String

The type of renderer.

more details
PieChartRenderer
SizeVariable[]

An array of Size Visual Variable objects.

more details
PieChartRenderer

Property Details

Defines the variable(s) to include in the pie charts. This is an array of objects, each of which references a numeric field value or Arcade expression used to drive the width of each sector. You must also set a color corresponding to each value.

This property is limited to no more than 10 attributes.

See also
Example
renderer.attributes = [{
  field: "English",
  label: "English speakers",
  color: "red"
}, {
  field: "Spanish",
  label: "Spanish speakers",
  color: "blue"
}, {
  field: "Other",
  label: "All other languages",
  color: "brown"
}];

Authoring metadata only included in renderers generated from one of the Smart Mapping creator methods, such as sizeRendererCreator.createContinuousRenderer() or colorRendererCreator.createContinuousRenderer(). This includes information from UI elements such as sliders and selected classification methods and themes. This allows the authoring clients to save specific overridable settings so that next time it is accessed via the UI, their selections can be remembered.

backgroundFillSymbol SimpleFillSymbolautocast

The symbol used to render polygons behind the pie symbols. Only applicable to polygon layers.

Example
renderer.backgroundFillSymbol = {
  color: [51, 204, 51, 0.3],
  outline: {
    width: 1,
    color: [255,255,255,0.3]
  }
};
declaredClass Stringreadonly inherited

The name of the class. The declared class name is formatted as esri.folder.className.

defaultColor Color

The color used to visualize features whose attributes all have null or empty values. By default, this is a transparent color, so no chart displays. You should set this value if you would like to show areas with features, but no data associated with it.

Default Value:new Color([0, 0, 0, 0])
See also
Example
renderer.defaultColor = "lightgray";
defaultLabel String

Describes the defaultColor in the Legend.

Example
renderer.defaultLabel = "No data";
holePercentage Number

Use this property to create a donut chart. Defines the size of the hole to cut from the center of the chart as a percentage of the entire pie chart. Accepted values are between 0 and 1. For example, a hole percentage of 0 will render a full pie chart. A ratio of 0.5 will remove 50% of the center of the pie, creating a donut.

Default Value:0
Example
renderer.holePercentage = 0.5;
legendOptions Object

An object providing options for describing the renderer in the Legend.

Property
title String
optional

Describes the data used by the renderer. This is displayed as the title of the renderer in the Legend and overrides the layer's title.

Example
renderer.legendOptions = {
  title: "Population by educational attainment"
};
othersCategory Object

Defines the rules for how to aggregate small categories to a generic "others" category.

Properties
color Color
optional

Defines the color used to represent all categories whose pie slices are smaller than the percentage defined by threshold. This is typically used to represent a generic "others" category where slices would otherwise be too small to read.

label String
optional

Describes the color grouping categories smaller than the threshold in the Legend.

threshold Number
optional

Represents the minimum size of individual slices as a percentage of the entire pie. Accepted values are between 0 and 1. All slices that make up a smaller percentage than the threshold will automatically be aggregated to an "others" category represented by the color specified in color. For example, if the threshold is 0.05, then all slices that make up less than 5% of the total pie will be represented with the color.

Example
// all categories that make up less than 4%
// of the total will combine to an "others"
// category represented with a gray color.
renderer.othersCategory = {
  color: "gray",
  threshold: 0.04
};

Defines the outline of the pie chart. The outline width and color is applied to the outer outline of the pie (and inner outline in the case of donut charts).

Example
renderer.outline = {
  width: 0.5,
  color: "black"
};
Autocasts from String|Number

Defines the size of each pie chart in points. This value may be autocast with a string expressing size in points or pixels (e.g. 12px).

Default Value:12
Examples
// size in points
renderer.size = 14;
// size in pixels
renderer.size = "20px";
// size in points
renderer.size = "14pt";
type Stringreadonly

The type of renderer.

For PieChartRenderer the type is always "pie-chart".

visualVariables SizeVariable[]autocast
Autocasts from Object[]

An array of Size Visual Variable objects. Typically, this is used to vary the size of each pie chart based on the sum of all categories included in the pie.

Example
renderer.visualVariables = [{
  type: "size",
  valueExpression: "$feature.category1 + $feature.category2 + $feature.category3",
  valueExpressionTitle: "Total population"
  minSize: 20,
  maxSize: 72,
  minDataValue: 100,
  maxDataValue: 1000000
}];

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

more details
Accessor
PieChartRenderer

Creates a deep clone of the renderer.

more details
PieChartRenderer
*

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product.

more details
Renderer
Boolean

Returns true if a named group of handles exist.

more details
Accessor

Removes a group of handles owned by the object.

more details
Accessor
Object

Converts an instance of this class to its ArcGIS portal JSON representation.

more details
Renderer

Method Details

addHandles(handleOrHandles, groupKey)inherited
Since: ArcGIS API for JavaScript 4.25

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

// Handle gets removed when the object is destroyed.
this.addHandles(handle);
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

clone(){PieChartRenderer}

Creates a deep clone of the renderer.

Returns
Type Description
PieChartRenderer A deep clone of the object that invoked this method.
Example
// Creates a deep clone of the first layer's renderer
let renderer = view.map.layers.getItemAt(0).renderer.clone();
fromJSON(json){*}static

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
Type Description
* Returns a new instance of this class.
hasHandles(groupKey){Boolean}inherited
Since: ArcGIS API for JavaScript 4.25

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}
removeHandles(groupKey)inherited
Since: ArcGIS API for JavaScript 4.25

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");
toJSON(){Object}inherited

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
Type Description
Object The ArcGIS portal JSON representation of an instance of this class.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.