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

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

Creates a bar mark that plots values on y with fixed x interval.

```
nonisolated init<Y>(xStart: CGFloat? = nil, xEnd: CGFloat? = nil, y: PlottableValue<Y>, height: MarkDimension = .automatic, stacking: MarkStackingMethod = .standard) where Y : Plottable
```

## Parameters

`xStart`

The x start position. If `xStart` is `nil` then the rectangle will start at the leading edge of the plotting area.

`xEnd`

The x end position. If `xStart` is `nil` then the rectangle will end at the trailing edge of the plotting area.

`y`

The value plotted with y.

`height`

The bar height.  If `height` is `nil`, the default bar size will be applied.

`stacking`

The stacking method for the bars with the same categorical/date values.
If `stacking` is `nil`, the bars will not be stacked.

## Discussion

### Discussion

Use this initializer to create a chart with a single vertical bar:

```swift
Chart(data) {
    BarMark(
        y: .value("Profit", $0.profit)
    )
    .foregroundStyle(by: .value("Product Category", $0.productCategory))
}
```

![Vertical bar chart with one bar on the y-axis showing profit ranging from 0 to 15000 with stacked categories Gizmos, Gadgets and Widgets. Legend showing the color mapped to a product category.](images/com.apple.Charts/BarMarkSwift.BarMarkVerticalStacked1DBarChartWithForegroundColor@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)