<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Charts",
  "identifier" : "/documentation/Charts/RectangleMark/init(x:y:width:height:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift Charts"
    ],
    "preciseIdentifier" : "s:6Charts13RectangleMarkV1x1y5width6heightAcA14PlottableValueVyxG_AIyq_GAA0C9DimensionVAMtcAA0F0RzAaNR_r0_lufc"
  },
  "title" : "init(x:y:width:height:)"
}
-->

# init(x:y:width:height:)

Creates a rectangle that plots values with x and y.

```
nonisolated init<X, Y>(x: PlottableValue<X>, y: PlottableValue<Y>, width: MarkDimension = .automatic, height: MarkDimension = .automatic) where X : Plottable, Y : Plottable
```

## Parameters

`x`

The value plotted with x.

`y`

The value plotted with y.

`width`

The rectangle width.  If `width` is not specified, then 70% of the step size will be used. If there is no step size a default width (in pts) will be used.

`height`

The rectangle height.  If `height` is not specified, then 70% of the step size will be used. If there is no step size a default height (in pts) will be used.

## Discussion

### Discussion

Use this initializer to map an x and y position to a rectangle for each data element. Optionally, specify the width or height of the rectangles.

The example below omits the optional `width` and `height` parameters and uses a number scale starting at (0,0). The rectangle has the coordinates:
(0,0), (0,3), (3,0), (3,3).

```swift
Chart(data) {
    RectangleMark(
        x: .value("Rect X", 3),
        y: .value("Rect Y", 3)
    )
    .opacity(0.2)

    PointMark(
        x: .value("X", $0.x),
        y: .value("Y", $0.y)
    )
}
```

![Scatter plot chart with a rectangle mark annotation. 3 points on the chart at: (5, 5), (2.5, 2.5), (3, 3) the rectangle highlights a rectangular area with coordinates: (0,0), (0,3), (3,0), (3,3).](images/com.apple.Charts/RectangleMarkSwift.RectangleMarkScatterWithRectangleXY@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)