Skip to main content

LegendItem

サマリー

LegendItem provides access to legend item level information in a LegendElement.

ディスカッション

The items property on the LegendElement class returns a list of LegendItem objects. For each legend item, you can change properties such as arrangement, patchHeight, and its visible status. The typical workflow is to iterate through the list of elements, determine the item of interest by its name property, then make the appropriate changes.

注意:

The properties exposed to the LegendItem class do not apply to all renderer types. It is important to catch these exceptions when necessary.

プロパティ

名前 説明 データ タイプ

arrangement

(読み取り/書き込み)

A string that determines the legend item arrangement. The following is a valid list of values:

  • PatchLabelDescription—Patch, label, description

  • PatchDescriptionLabel—Patch, description, label

  • LabelPatchDescription—Label, patch, description

  • LabelDescriptionPatch—Label, description, patch

  • DescriptionPatchLabel—Description, patch, label

  • DescriptionLabelPatch—Description, label, patch

String

column

(読み取り/書き込み)

The column position for a legend item. The column property only applies to legends using the ManualColumns fitting strategy.

Long

name

(読み取り専用)

Returns the legend item name. The legend item name is set by modifying the layer name.

String

patchHeight

(読み取り/書き込み)

The height of a legend item patch. Units are in points.

Double

patchWidth

(読み取り/書き込み)

The width of a legend item patch. Units are in points.

Double

showFeatureCount

(読み取り/書き込み)

A Boolean that controls whether the feature count is placed next to the legend item text. The value displayed is dependent on the showVisibleFeatures setting.

Boolean

showVisibleFeatures

(読み取り/書き込み)

A Boolean that controls whether the legend item displays all values or only those values that appear in the visible extent.

Boolean

type

(読み取り専用)

Returns a value of LEGEND_ITEM.

String

visible

(読み取り/書き込み)

Returns True if the legend item is visible in the legend.

Boolean

方法

applyStyleItem(style_item)

Applies a StyleItem to a LegendItem.

When referencing a StyleItem using the listStyleItems method on the ArcGISProject class, the style_class parameter must be LEGEND_ITEM. For more information and code samples, refer the to StyleItem help topic.

注意:

Styles must be added to a project prior to using the applyStyleItem method. Styles can be added using the updateStyles method on the ArcGISProject class.

名前 説明 データ タイプ

style_item

A reference to a StyleItem in a project.

StyleItem

コードのサンプル

LegendItem example

The following script iterates through all legend items in a legend. Its sets the patchHeight and patchWidth for all legend items, then sets showVisibleFeatures for a specific legend item.

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]
leg = lyt.listElements('LEGEND_ELEMENT')[0]

#Change the patch size for all legend items
#only display features in the visible map frame extent
for itm in leg.items:
  itm.patchHeight = 15
  itm.patchWidth = 30
  if itm.name == 'Geological Types':
    itm.showVisibleFeatures = True