Skip to main content

Line

汇总

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

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

讨论

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

语法

Line(x, {y}, {splitCategory}, {multiSeriesDisplay}, {miniChartsPerRow}, {showPreviewChart}, {aggregation}, {timeIntervalUnits}, {timeIntervalSize}, {timeAggregationType}, {trimIncompleteTimeInterval}, {nullPolicy}, {showMovingAverage}, {movingAveragePeriod}, {rotated}, {title}, {description}, {xTitle}, {yTitle}, {dataSource}, {displaySize}, {theme})

名称 说明 数据类型

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.

  • singleChart—All series will be displayed in a single chart.

  • grid—The series will be displayed as a grid of mini charts.

String

miniChartsPerRow

(可选)

每行显示的迷你图表的数量。

Integer

showPreviewChart

(可选)

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

  • True—The preview chart will be displayed.

  • False—The preview chart will not be displayed.

(默认值为 False)

Boolean

aggregation

(可选)

Specifies the statistical calculation that will be applied to values aggregated into each temporal or numeric bin.

  • <None>—Each value will be plotted on the chart regardless of overlap or recurring values.

  • COUNT—The total number of records will be identified and applied.

  • SUM—The sum of all values will be calculated and applied.

  • MEAN—The mean of all values will be calculated and applied.

  • MEDIAN—The median of all values will be identified and applied.

  • MIN—The minimum value will be identified and applied.

  • MAX—The maximum value will be identified and applied.

String

timeIntervalUnits

(可选)

Specifies the time unit that corresponds to the timeIntervalSize value.

  • SECONDS—The time unit will be seconds.

  • MINUTES—The time unit will be minutes.

  • HOURS—The time unit will be hours.

  • DAYS—The time unit will be days.

  • WEEKS—The time unit will be weeks.

  • MONTHS—The time unit will be months.

  • YEARS—The time unit will be years.

String

timeIntervalSize

(可选)

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

String

timeAggregationType

(可选)

Specifies the time interval alignment type.

  • equalIntervalsFromStartTime—The time interval will be aligned to the start date.

  • equalIntervalsFromEndTime—The time interval will be 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) will be 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.

  • True—Incomplete intervals will be removed.

  • False—Incomplete intervals will not be removed.

String

nullPolicy

(可选)

Specifies how summarized bins returning a null value will be displayed.

  • null—Missing values will be treated as null.

  • zero—Missing values will be treated as zero.

  • interpolate—Interpolation will be used to fill missing values.

String

showMovingAverage

(可选)

Specifies whether the moving average line will be displayed for temporal line charts.

  • True—The moving average line will be displayed.

  • False—The moving average line will not be displayed; it will be hidden.

(默认值为 False)

Boolean

movingAveragePeriod

(可选)

The size of the moving average period.

Integer

rotated

(可选)

Specifies whether lines will be displayed horizontally or vertically.

  • True—Lines will be displayed vertically.

  • False—Lines will be displayed horizontally.

(默认值为 False)

Boolean

title

(可选)

图表的标题。 标题文本显示在图表视图的顶部,并在 内容 窗格中用作图表的标注。

String

description

(可选)

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

String

xTitle

(可选)

图表 x 轴的标题。

String

yTitle

(可选)

图表 y 轴的标题。

String

dataSource

(可选)

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

  • 数据集的路径(包括本地数据集、UNC 路径和服务 URL)

  • Apache Arrow 表对象

  • LayerTable 对象

Object

displaySize

(可选)

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

List

theme

(可选)

指定将应用于图表的主题。

  • Light—The Light theme will be applied.

  • Medium—The Medium theme will be applied.

  • Dark—The Dark theme will be applied.

String

属性

名称 说明 数据类型

aggregation

(读取和写入)

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

  • <None>—每个值都将在图表中绘制,无论值是否重叠或循环。

  • COUNT—将识别并应用总记录数。

  • SUM—将计算并应用所有值的总和。

  • MEAN—将计算并应用所有值的平均值。

  • MEDIAN—将识别并应用所有值的中值。

  • MIN—将识别并应用最小值。

  • MAX—将识别并应用最大值。

String

color

(读取和写入)

将应用于每个图表系列的颜色。 该值应为十六进制字符串值的列表。 如果未设置此属性,则系列颜色将匹配符号系统颜色(如果适用)。否则,将应用标准调色板。

List

dataSource

(读取和写入)

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

  • 数据集的路径(包括本地数据集、UNC 路径和服务 URL)

  • Apache Arrow 表对象

  • LayerTable 对象

Object

description

(读取和写入)

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

String

displaySize

(读取和写入)

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

List

enableServerSideProcessing

(读取和写入)

指定当数据来自企业级数据库或云数据仓库时,是否将使用 服务器端处理

  • True—将启用服务器端处理。

  • False—将禁用服务器端处理。

Boolean

legend

(读取和写入)

图表图例的属性。

  • alignment - 指定图例的对齐。 对齐选项为 leftbottomtopright

  • title - 图例的标题。

  • visible - 指定是否在图表视图中显示图例。 True 显示图例, False 隐藏图例。

Object

miniChartsPerRow

(读取和写入)

每行显示的迷你图表的数量。

Integer

movingAveragePeriod

(读取和写入)

移动平均时间段大小。

Integer

multiSeriesDisplay

(读取和写入)

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

  • singleChart—所有系列将在单一图表中显示。

  • grid—系列将显示为迷你图表网格。

String

nullPolicy

(读取和写入)

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

  • null—缺失值将视为空值。

  • zero—缺失值将视为零。

  • interpolate—插值将用于填充缺失值。

String

rotated

(读取和写入)

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

  • True—将以水平方式显示图表。

  • False—将以垂直方式显示图表。

Boolean

showPreviewChart

(读取和写入)

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

  • True—将显示预览图表。

  • False—不会显示预览图表。

Boolean

splitCategory

(读取和写入)

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

String

theme

(读取和写入)

指定将应用于图表的主题。

  • Light—将应用浅色主题。

  • Medium—将应用中等主题。

  • Dark—将应用深色主题。

String

showMovingAverage

(读取和写入)

指定是否将针对时间折线图显示移动平均线。

  • True—将显示移动平均线。

  • False—不会显示移动平均线;它将处于隐藏状态。

Boolean

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 轴的属性。

  • addGuide - 使用 Guide 对象向轴添加一条参考线。

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

  • logarithmic - 指定轴是否为对数轴。 True 将显示对数轴。 False 将显示线性轴。

  • listGuides - 轴的 Guide 对象的列表。

  • maximum - 最大轴边界。

  • minimum - 最小轴边界。

  • removeGuide - 移除 Guide 对象参数指定的参考线。

  • sort - Line 类不支持此属性。

  • title - 图表中所显示的轴的标注。

Object

y

(读取和写入)

y 轴变量的字段名称或名称。 该值必须是数值字段或数值字段列表。

String

yAxis

(读取和写入)

指定 y 轴的属性。

  • addGuide - 使用 Guide 对象向轴添加一条参考线。

  • field - y 轴变量的字段名称或名称。 提供单个数值字段或数值字段列表。

  • invert - 指定是否对轴进行反转。 True 将对轴进行反转, False 不会对轴进行反转。

  • logarithmic - 指定轴是否为对数轴。 True 将显示对数轴。 False 将显示线性轴。

  • listGuides - 轴的 Guide 对象的列表。

  • maximum - 最大轴边界。

  • minimum - 最小轴边界。

  • removeGuide - 移除 Guide 对象参数指定的参考线。

  • sort - Line 类不支持此属性。

  • title - 图表中所显示的轴的标注。

  • useAdaptiveBounds - 指定格网图表是带自适应还是固定轴边界显示。 True 显示带自适应边界的轴。 False 显示带固定边界的轴。

Object

方法

addToLayer(layer_or_layerfile)

addToLayer 方法可将图表对象添加到图层或表视图。

名称 说明 数据类型

layer_or_layerfile

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

Object

将图表添加到现有图层。

import arcpy

# Insert creation of chart object here
# ...

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)

exportToJPEG(path, width, height)

exportToJPEG 方法用于将图表导出为 JPEG 格式。

名称 说明 数据类型

path

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

String

width

The width of the output graphic.

Integer

height

The height of the output graphic.

Integer

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

import arcpy

# Insert creation of chart object here
# ...

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.exportToJPEG('theftsPerBeat.jpg', 800, 600)

exportToPNG(path, width, height)

exportToPNG 方法用于将图表导出为 PNG 格式。

名称 说明 数据类型

path

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

String

width

The width of the output graphic.

Integer

height

The height of the output graphic.

Integer

从图层访问现有图表,更新标题,然后将其导出为 .png 文件。

import arcpy

lyr = arcpy.mp.ArcGISProject('current').listLayers()[0]

# Retrieve the first chart belonging to the layer
chart = lyr.listCharts()[0]

# Update chart title
chart.title = 'Voter Turnout by State'

# Save the chart to PNG file with dimensions width=800, height=600
chart.exportToPNG('populationByState.png', 800, 600)

exportToSVG(path, width, height)

exportToSVG 方法可将图表导出为 SVG 格式。

名称 说明 数据类型

path

将图表以 SVG 格式导出时的路径。

String

width

输出图形的宽度。

Integer

height

输出图形的高度。

Integer

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

import arcpy

# Insert creation of chart object here
# ...

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

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

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

updateChart()

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

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

import arcpy

# Insert creation of chart object here
# ...

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)