---
title: "chartLegend(position:alignment:spacing:content:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/chartlegend(position:alignment:spacing:content:)"
---

# chartLegend(position:alignment:spacing:content:)

Configures the legend for charts.

## Declaration

```swift
nonisolated func chartLegend<Content>(position: AnnotationPosition = .automatic, alignment: Alignment? = nil, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content) -> some View where Content : View

```

## Parameters

- `position`: Configures the position of the legend.
- `alignment`: Alignment of the legend within the space available to it. Use nil for default alignment.
- `spacing`: Distance between the legend and the chart. Use nil for the default spacing.
- `content`: The content of the legend.

## See Also

### Legends

- [chartLegend(_:)](swiftui/view/chartlegend(_:).md)
- [chartLegend(position:alignment:spacing:)](swiftui/view/chartlegend(position:alignment:spacing:).md)
