Line

摘要

折线图可用于显示随着时间或距离等连续范围发生的变化。 使用折线图来显示变化可以立即显示总体趋势,还可同时对多个趋势进行比较。

了解有关 ArcGIS Pro 中折线图的详细信息

说明

创建图表对象时,必须使用参数名指定类构造函数的可选参数;这些可选参数不能通过参数位置指定。 有关如何使用关键字指定参数的示例,请参阅代码示例部分。

语法

 Line (x, {y}, {splitCategory}, {multiSeriesDisplay}, {miniChartsPerRow}, {showPreviewChart}, {aggregation}, {timeIntervalUnits}, {timeIntervalSize}, {timeAggregationType}, {trimIncompleteTimeInterval}, {nullPolicy}, {rotated}, {title}, {description}, {xTitle}, {yTitle}, {dataSource}, {displaySize})
参数说明数据类型
x

The field name for the x-axis variable. The field must be a numeric or date field.

String
y

The field name or names for the y-axis variables. The value must be a numeric field or a list of numeric fields.

String
splitCategory

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

String
multiSeriesDisplay

Specifies the display type for a line chart with multiple series.

  • singleChartAll series are displayed in a single chart.
  • gridThe series are displayed as a grid of miniplots.
String
miniChartsPerRow

The number of minicharts that will be shown per row. The number of rows will be determined by the total number of series divided by the miniChartsPerRow value.

Integer
showPreviewChart

Specifies whether the preview chart will be displayed for grid charts.

  • TrueThe preview chart will be displayed.
  • FalseThe preview chart will not be displayed.

(默认值为 False)

Boolean
aggregation

Specifies the statistical calculation that is applied to values aggregated into each temporal bin.

  • <None>Each value is plotted on the chart regardless of overlap or recurring values.
  • COUNTThe total number of records is identified and applied.
  • SUMThe sum of all values is calculated and applied.
  • MEANThe mean of all values is calculated and applied.
  • MEDIANThe median of all values is identified and applied.
  • MINThe minimum value is identified and applied.
  • MAXThe maximum value is identified and applied.
String
timeIntervalUnits

Specifies the time unit that corresponds to the timeIntervalSize.

  • SECONDSThe time unit is seconds.
  • MINUTESThe time unit is minutes.
  • HOURSThe time unit is hours.
  • DAYSThe time unit is days.
  • WEEKSThe time unit is weeks.
  • MONTHSThe time unit is months.
  • YEARSThe time unit is years.
String
timeIntervalSize

The span of time that is binned or aggregated together. This argument must be used in conjunction with timeIntervalUnits.

String
timeAggregationType

Specifies the time interval alignment type.

  • equalIntervalsFromStartTimeThe time interval is aligned to the start date.
  • equalIntervalsFromEndTimeThe time interval is aligned to the end date.
String
trimIncompleteTimeInterval

Specifies whether incomplete time intervals at the start or end of the data span (depending on the timeAggregationType value) are removed (trimmed) from the chart. Incomplete intervals on a chart can cause misleading results in which the period in question is underreported or overreported due to a different amount of time in the interval.

  • TrueIncomplete intervals are removed.
  • FalseIncomplete intervals are not removed.
String
nullPolicy

Specifies how summarized bins returning a null value are displayed.

  • nullMissing values are treated as null.
  • zeroMissing values are treated as zero.
  • interpolateInterpolation is used to fill missing values.
String
rotated

Specifies whether lines are displayed horizontally or vertically.

  • TrueLines are displayed vertically.
  • FalseLines are displayed horizontally.

(默认值为 False)

Boolean
title

The title of the chart. The title text appears at the top of the chart view and is used as the label for the chart in the Contents pane.

String
description

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

String
xTitle

The title of the x-axis of the chart.

String
yTitle

The title of the y-axis of the chart.

String
dataSource

The data source of the chart. When a chart is exported using the exportToSVG method or displayed in an ArcGIS Notebook, the data source will be read and rendered on the chart. Valid data sources include the following:

  • Paths to datasets, including local datasets, UNC paths, and service URLs
  • Arrow table objects
  • Layer objects

Object
displaySize
[displaySize,...]

The size of the chart when exported using the exportToSVG method or displayed in an ArcGIS Notebook. The value must be specified as a two-item list in which the first item is the width of the chart and the second item is the height of the chart.

List

属性

属性说明数据类型
aggregation
(可读写)

指定应用于聚合到每个时间立方图格中的值的统计计算。

  • <None>每个值都会在图表中绘制,无论值是否重叠或循环。
  • COUNT将识别并应用总记录数。
  • SUM将计算并应用所有值的总和。
  • MEAN将计算并应用所有值的平均值。
  • MEDIAN将识别并应用所有值的中值。
  • MIN将识别并应用最小值。
  • MAX将识别并应用最大值。
String
dataSource
(可读写)

图表的数据源。 当通过 exportToSVG 方法导出图表或将其显示在 ArcGIS Notebook 中时,将读取数据源并将其呈现在图表上。 其中包括以下有效数据源:

  • 数据集的路径(包括本地数据集、UNC 路径和服务 URL)
  • Arrow 表对象
  • Layer 对象。

Object
description
(可读写)

图表的描述。 该描述文本会显示于图表视图底部。

String
displaySize
(可读写)

当使用 exportToSVG 方法导出图表或将其显示在 ArcGIS Notebook 中时,图表的大小。 该值必须指定为两个项目的列表,其中第一个项目是图表的宽度,第二个项目是图表的高度。

List
legend
(可读写)

图表图例的属性。

  • visible - 指定是否在图表视图中显示图例。 True 显示图例,False 隐藏图例。
  • title - 图例的标题。
Object
miniChartsPerRow
(可读写)

每行显示的迷你图表的数量。 行数将由系列总数除以 miniChartsPerRow 值确定。

Integer
multiSeriesDisplay
(可读写)

指定具有多个系列的折线图的显示类型。

  • singleChart所有系列将在单一图表中显示。
  • grid系列将显示为迷你图格网。
String
nullPolicy
(可读写)

指定返回空值的汇总立方图格的显示方式。

  • null缺失值将视为空值。
  • zero缺失值将视为零。
  • interpolate插值用于填充缺失值。
String
rotated
(可读写)

指定将以垂直方式还是水平方式显示图表。

  • True将以水平方式显示图表。
  • False将以垂直方式显示图表。
Boolean
showPreviewChart
(可读写)

指定是否在格网图表中显示预览图表。

  • True将显示预览图表。
  • False不会显示预览图表。
Boolean
splitCategory
(可读写)

类别字段,将为字段中每一个唯一值添加单独的系列或线。

String
theme
(可读写)

指定应用于图表的主题的名称。

String
timeAggregationType
(可读写)

指定时间间隔对齐类型。

  • equalIntervalsFromStartTime时间间隔已对齐到起始日期。
  • equalIntervalsFromEndTime时间间隔已对齐到结束日期。
String
timeIntervalSize
(可读写)

将分组或聚合在一起的时间跨度。 该属性必须与 timeIntervalUnits 结合使用。

String
timeIntervalUnits
(可读写)

指定与 timeIntervalSize 值对应的时间单位。

  • SECONDS时间单位为秒。
  • MINUTES时间单位为分钟。
  • HOURS时间单位为小时。
  • DAYS时间单位为天。
  • WEEKS时间单位为周。
  • MONTHS时间单位为月。
  • YEARS时间单位为年。
String
title
(可读写)

图表的标题。 标题文本显示于图表视图顶部,并用作内容窗格中按绘制顺序列出选项卡 按绘制顺序列出 的标注。

String
trimIncompleteTimeInterval
(可读写)

指定是否将从图表中移除(修剪)数据跨度开始或结束位置的不完整时间间隔(取决于 timeAggregationType 值)。 图表中的不完整间隔会导致令人误解的结果,其中,由于间隔时间不同,时间段问题会被低估或高估。

  • True不完整间隔已移除。
  • False不完整间隔未移除。
String
type
(只读)

用于指示图表类型的字符串值。

String
x
(可读写)

x 轴变量的字段名称。 该字段必须为数值或日期字段。

String
xAxis
(可读写)

设置 x 轴的属性。

  • field - x 轴变量的字段名称。 该字段必须为数值或日期字段。
  • logarithmic - 指定轴是否为对数轴。 True 将显示对数轴。 False 将显示线性轴。
  • maximum - 最大轴边界。
  • minimum - 最小轴边界。
  • sort - Line 类不支持此属性。
  • title - 图表中所显示的轴的标注。
Object
y
(可读写)

一个或多个数值字段的字段名称。 提供一个字段名或一个字段名称列表。

String
yAxis
(可读写)

设置 y 轴的属性。

  • field - 一个或多个数值字段的字段名称。 提供一个字段名或一个字段名称列表。
  • logarithmic - 指定轴是否为对数轴。 True 将显示对数轴。 False 将显示线性轴。
  • maximum - 最大轴边界。
  • minimum - 最小轴边界。
  • sort - Line 类不支持此属性。
  • title - 图表中所显示的轴的标注。
  • useAdaptiveBounds - 指定格网图表是带自适应还是固定轴边界显示。 True 显示带自适应边界的轴。 False 显示带固定边界的轴。
Object

方法概述

方法说明
addToLayer (layer_or_layerfile)

将图表对象添加到图层或独立表中。

exportToSVG (path, width, height)

将图表导出为 SVG 格式。

updateChart ()

更新图表属性可以同步对象与之前添加到图层的图表之间的更改。

方法

addToLayer (layer_or_layerfile)
参数说明数据类型
layer_or_layerfile

The chart will be added to the target object. The layer_or_layerfile argument can be a Layer or a Table object.

Object

定义图表属性后的最后一步通常是使用 addToLayer 方法将图表对象添加到图层或表中。

将图表添加到现有图层。

import arcpy

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

# Add chart object to a layer
chart.addToLayer(censusLayer)
exportToSVG (path, width, height)
参数说明数据类型
path

The path where the chart will be exported in SVG format.

String
width

The width of the output graphic.

Integer
height

The height of the output graphic.

Integer

在某些情况下,您可能希望将图表另存为可在 ArcGIS Pro 外部共享和查看的图形。 导出为 SVG 图形格式是有好处的,因为图表元素和文本将存储为可在矢量图形软件中进行独立修改的矢量元素。 SVG 图形也可以调整为任何比例,而不会出现像素化或质量下降的情况。

将具有工程图层数据源的图表导出到 .svg 文件中。

import arcpy

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

# Set data source of chart object to a layer within current project
chart.dataSource = censusLayer

# Save the chart to file with dimensions width=500, height=500
chart.exportToSVG('populationByState.svg', 500, 500)

将具有要素服务数据源的图表导出到 .svg 文件中。


featureServiceURL = r'https://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/CrimesChiTheft/FeatureServer/0'

# Set data source of chart object to a feature service URL
chart.dataSource = featureServiceURL

# Save the chart to file with dimensions width=800, height=600
chart.exportToSVG('theftsPerBeat.svg', 800, 600)
updateChart ()

定义图表属性后的最后一步通常是使用 addToLayer 方法将图表对象添加到图层中。

要进一步修改图表属性,您可以修改原始图表的属性,而非从头开始创建新图表。 然后,您可以使用 updateChart 方法将所有更改同步到已添加到该图层的图表中。 由此可在图表属性窗格和图表视图中显示所做的更改。

可以使用 updateChart 方法将图表属性更改同步到图层中。


chart.addToLayer(myLayer)

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

代码示例

创建折线图,并将其添加到当前工程中的图层。

import arcpy

lyr = arcpy.mp.ArcGISProject("current").listMaps()[0].listLayers()[0]
chart = arcpy.charts.Line(x="date", y="aqi", aggregation="mean")
chart.addToLayer(lyr)