<!--
{
  "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(xStart:xEnd:y:height:)-27222",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift Charts"
    ],
    "preciseIdentifier" : "s:6Charts13RectangleMarkV6xStart4xEnd1y6heightAcA14PlottableValueVyxG_AjIyq_GAA0C9DimensionVtcAA0G0RzAaNR_r0_lufc"
  },
  "title" : "init(xStart:xEnd:y:height:)"
}
-->

# init(xStart:xEnd:y:height:)

Creates a rectangle mark with an x interval encoding and a y encoding.

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

## Parameters

`xStart`

The value plotted with x start.

`xEnd`

The value plotted with x end.

`y`

The value plotted with y.

`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 the x start, x end and y position to a rectangle for each data element. Optionally, specify the height of the rectangles.

The example below omits the optional `height` parameter and uses a number scale starting at (0,0) and ending at (6,6). The rectangle has the coordinates:
(2,0), (2,4), (4,4), (4,0).

```swift
Chart(data) {
    RectangleMark(
        xStart: .value("Rect xStart", 2),
        xEnd: .value("Rect xEnd", 4),
        y: .value("Rect Y", 4)
    )
    .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: (2,0), (2,4), (4,4), (4,0).](images/com.apple.Charts/RectangleMarkSwift.RectangleMarkScatterWithRectangleXIntervalY@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)