Skip To Content

Chart

Summary

The Chart class defines an ArcGIS Pro chart. The class allows you to create different types of charts, including bar charts, line charts, histograms, and scatter plots. Also, you can use the class to define the chart title, axes, and other properties.

Learn more about charts in ArcGIS Pro

Discussion

Charts assist you in presenting information about map features and the relationship between them in a visual, easy-to-understand manner. Charts may also be created for nonspatial tables and can show both additional information about the features on the map or the same information in a different way. Charts are complementary to maps in that they simply and visually convey information that would generally be summarized numerically or explored from tables. With a chart, it is easy to quickly compare features to gain insight into the functional relationship between the features and thereby visualize the distribution, trends, and patterns in the data that would otherwise be difficult to see.

You can only create and add charts to layer or tables in an ArcGIS Pro project and map. Charts cannot be visualized, rendered, or exported outside of the ArcGIS Pro application.

Syntax

 Chart (name)
ParameterExplanationData Type
name

The name of the chart. A chart must have a unique name per layer. This name is only used for identification; it is not displayed.

String

Properties

PropertyExplanationData Type
bar
(Read and Write)

Sets additional properties that apply to bar charts only.

bar propertyDescription

aggregation

The statistical calculation applied to values that occur at the same value along the x-axis. Valid statistics include COUNT, SUM, MEAN, and MEDIAN. No aggregation means that each value will be plotted on the chart regardless of overlap or recurring values.

splitCategory

A second categorical attribute field that adds a separate series or bar for each unique value in the field.

Object
description
(Read and Write)

Sets the description of the chart. The description text appears at the bottom of the chart view.

String
histogram
(Read and Write)

Sets additional properties that apply to histograms only.

histogram propertyDescription

binCount

Number that determines the number of bins to display in the histogram.

showMean

Toggles if the mean statistical line is visible in the histogram. True displays the line, False hides the line.

showMedian

Toggles if the median statistical line is visible in the histogram. True displays the line, False hides the line.

showStandardDeviation

Toggles if the standard deviation statistical line is visible in the histogram. True displays the line, False hides the line.

Object
legend
(Read and Write)

Sets properties of the chart legend.

legend propertyDescription

visible

Toggles if the legend is visible in the chart view. True displays the legend, False hides the legend.

Object
line
(Read and Write)

Sets additional properties that apply to line charts only.

line propertyDescription

aggregation

The statistical calculation applied to values that occur at the same value along the x-axis. Valid statistics include COUNT, SUM, MEAN, and MEDIAN. No aggregation means that each value will be plotted on the chart regardless of overlap or recurring values.

splitCategory

A second categorical attribute field that adds a separate series or bar for each unique value in the field.

timeAggregationType

Determines the time interval alignment. Valid options include equalIntervalsFromStartTime and equalIntervalsFromEndTime.

timeIntervalSize

A number for the span of time that will be binned or aggregated together. Must be used in conjunction with timeIntervalUnit.

timeIntervalUnits

The time unit that corresponds to the timeIntervalSize. Valid options include SECONDS, MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS.

trimInCompleteTimeInterval

Determines if incomplete time intervals at the start or end of the data span (depending on the timeAggregationType) will be removed from the chart. Incomplete intervals on a chart can cause misleading results in which the period in question is under or over-reported due to a different amount of time in the interval.

True indicates to trim these incomplete intervals, while False does not trim incomplete intervals.

Object
title
(Read and Write)

Sets the title of the chart. The title text appears at the top of the chart view, and is used as the label in the List By Charts tab List By Charts of the Contents pane.

String
type
(Read and Write)

Sets the type of chart to create. Valid options include:

  • bar
  • line
  • scatter
  • histogram

String
xAxis
(Read and Write)

Sets properties of the x-axis.

xAxis propertyDescription

field

The name of the attribute field to display on the x-axis.

sort

The sorting method applied to this axis. ASC for ascending sorting and DESC for descending sorting. This only applies to bar charts.

title

The label of the axis that displays on the chart.

Object
yAxis
(Read and Write)

Sets properties of the y-axis.

yAxis propertyDescription

field

The name of the attribute field to display on the y-axis. For bar or line charts, this can be specified as a list of field names, like ["Pop2000", "Pop2010"].

sort

The sorting method applied to this axis. ASC for ascending sorting and DESC for descending sorting. This only applies to bar charts.

title

The label of the axis that displays on the chart.

Object

Method Overview

MethodExplanation
addToLayer (layer)

Adds the chart class to a layer.

updateChart ()

Updates chart properties to sync changes between the class and the chart previously added to a layer.

Methods

addToLayer (layer)
ParameterExplanationData Type
layer

The chart will be added to this target Layer object.

Layer
Return Value
Data TypeExplanation
Object

The Chart class will be unchanged, but the class' properties will be set into the layer definition and a new chart will be created.

After defining chart properties in the Chart class, the final step typically is to add the chart to a layer. Use the addToLayer method to accomplish this.

Set chart properties and add the chart to an existing layer.

import arcpy

aprx = arcpy.mp.ArcGISProject("current")
censusLayer = map.listLayers('Census Block Groups')[0]

c = arcpy.Chart('MyChart')
c.type = 'bar'
c.xAxis.field = 'State'
c.yAxis.field = 'Population'
c.addToLayer(censusLayer)
updateChart ()
Return Value
Data TypeExplanation
Object

The Chart class is not modified in any way. Rather the settings from the class are synced to the chart previously added to a layer.

After defining chart properties in the Chart class, the final step is typically to add the chart to a layer. Use the addToLayer method to accomplish this. However, you may wish to further modify the chart properties. Instead of starting from scratch with a new chart, you can modify the properties of the original Chart class, then use updateChart to sync any changes into the chart added to the layer. This will allow the changes you make to be presented in the Chart properties pane and chart view.

Use updateChart to sync chart property changes into a layer.

chart.addToLayer(myLayer)

# Further modification is necessary
chart.description = "Data from the U.S. Census Bureau"
chart.updateChart()

Code sample

Chart example

You can add a Chart object to an arcpy.mp Layer object in order to add the chart to the layer.

import arcpy

aprx = arcpy.mp.ArcGISProject("current")
map = aprx.listMaps()[0]
censusLayer = map.listLayers('Census Block Groups')[0]
c = arcpy.Chart('MyChart')

c.type = 'scatter'
c.title = 'Relationship between Percent Vacant (Housing) and Population Density'
c.description = 'This chart examines the relationship between housing vacancy and population density.'
c.xAxis.field = 'Per_Vacant'
c.yAxis.field = 'Pop_Density'
c.xAxis.title = 'Vacant Housing %'
c.yAxis.title = 'Population Density (per Sq. Mile)'
c.xAxis.sort = 'DESC'
c.addToLayer(censusLayer)