说明
创建此对象时,必须使用参数名指定类构造函数的可选参数;这些可选参数不能通过参数位置指定。 有关如何使用关键字指定参数的示例,请参阅代码示例部分。
语法
Combo (x, {seriesLeft}, {seriesRight}, {timeBinningProperties}, {nullPolicy}, {title}, {description}, {xTitle}, {yTitleLeft}, {yTitleRight}, {dataSource}, {displaySize}, {theme})
参数 | 说明 | 数据类型 |
x | x 轴变量的字段名称。 该字段必须为字符串或日期字段。 | String |
seriesLeft [seriesLeft,...] | 可以使用 Series 对象列表设置左侧 y 轴的系列。 | List |
seriesRight [seriesRight,...] | 可以使用 Series 对象列表设置右侧 y 轴的系列。 | List |
timeBinningProperties | 将应用于时间组合图表的 TimeBinningProperties 对象。 | Object |
nullPolicy | 指定时间组合图表中返回空值的汇总立方图格的显示方式。
| String |
title |
图表的标题。 标题文本显示在图表视图的顶部,并在内容窗格中用作图表的标注。 | String |
description | 图表的描述。 该描述文本会显示于图表视图底部。 | String |
xTitle | 图表 x 轴的标题。 | String |
yTitleLeft | 图表左侧 y 轴的标题。 | String |
yTitleRight | 图表右侧 y 轴的标题。 | String |
dataSource | 图表的数据源。 当通过 exportToSVG 方法导出图表或将其显示在 ArcGIS Notebooks 中时,将读取数据源并将其呈现在图表上。 其中包括以下有效数据源: | Object |
displaySize [displaySize,...] | 当使用 exportToSVG 方法导出图表或将其显示在 ArcGIS Notebooks 中时,图表的大小。 该值必须指定为两个项目的列表,其中第一个项目是图表的宽度,第二个项目是图表的高度。 | List |
theme | 指定将应用于图表的主题。
| String |
属性
属性 | 说明 | 数据类型 |
dataSource (可读写) | 图表的数据源。 当通过 exportToSVG 方法导出图表或将其显示在 ArcGIS Notebook 中时,将读取数据源并将其呈现在图表上。 其中包括以下有效数据源: | Object |
description (可读写) | 图表的描述。 该描述文本会显示于图表视图底部。 | String |
displaySize (可读写) | 当使用 exportToSVG 方法导出图表或将其显示在 ArcGIS Notebook 中时,图表的大小。 该值必须指定为两个项目的列表,其中第一个项目是图表的宽度,第二个项目是图表的高度。 | List |
MISSING_PROPNAME (可读写) | List | |
legend (可读写) | 图表图例的属性。
| Object |
nullPolicy (可读写) | 指定时间组合图表中返回空值的汇总立方图格的显示方式。
| String |
timeBinningProperties (可读写) | 将应用于时间组合图表的 TimeBinningProperties 对象。 | Object |
type (只读) | 用于指示图表类型的字符串值。 | String |
theme (可读写) | 将应用于图表的主题的名称。 | String |
seriesLeft (可读写) | 可以使用 Series 对象列表设置左侧 y 轴的系列。 | List |
seriesRight (可读写) | 可以使用 Series 对象列表设置右侧 y 轴的系列。 | List |
x (可读写) | x 轴变量的字段名称。 该字段必须为字符串或日期字段。 | String |
xAxis (可读写) | 指定 x 轴的属性。
| Object |
yAxisLeft (可读写) | 指定 y 轴的属性。
| Object |
yAxisRight (可读写) | 指定 y 轴的属性。
| Object |
方法概述
方法 | 说明 |
addToLayer (layer_or_layerfile) | addToLayer 方法可将图表对象添加到图层或表视图。 |
exportToSVG (path, width, height) | exportToSVG 方法可将图表导出为 SVG 格式。 |
updateChart () | 该 updateChart 方法可更新图表属性,以同步对象与之前添加到图层的图表之间的更改。 |
方法
addToLayer (layer_or_layerfile)
参数 | 说明 | 数据类型 |
layer_or_layerfile | The chart will be added to the target object. This argument can be a Layer or Table object. | Object |
使用 addToLayer 方法将图表对象添加到图层或表通常是定义图表属性之后的最终步骤。
将图表添加到现有图层。
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)
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 AllSource 外部共享和查看的图形。 导出为 SVG 图形格式是有好处的,因为图表元素和文本将存储为可在矢量图形软件中进行独立修改的矢量元素。 SVG 图形也可以调整为任何比例,而不会出现像素化或质量下降的情况。
将具有工程图层数据源的图表导出到 .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)
将具有要素服务数据源的图表导出到 .svg 文件中。
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.exportToSVG('theftsPerBeat.svg', 800, 600)
updateChart ()
使用 addToLayer 方法将图表对象添加到图层通常是定义图表属性之后的最终步骤。
您也可以修改原始图表的属性,而不是从头开始创建新图表。 然后,您可以使用 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()
代码示例
通过配置 Series 对象创建组合图表,并将图表导出至 .svg 文件。
import arcpy
seriesLeft = [arcpy.charts.Series(y="", aggregation="count", seriesType="bar")]
seriesRight = [arcpy.charts.Series(y="prcp", aggregation="mean", seriesType="line")]
chart = arcpy.charts.Combo(x="day_for_trips", seriesLeft=seriesLeft, seriesRight=seriesRight,
title="Bike Trips and Precipitation",
yTitleLeft="Total Rides", yTitleRight="Average Precipitation",
dataSource="BikeTripData")
chart.exportToSVG("combo.svg", width=900, height=500)