<!--
{
  "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(x:yStart:yEnd:width:stacking:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift Charts"
    ],
    "preciseIdentifier" : "s:6Charts7BarMarkV1x6yStart4yEnd5width8stackingAcA14PlottableValueVyxG_14CoreFoundation7CGFloatVSgAoA0C9DimensionVAA0C14StackingMethodVtcAA0H0Rzlufc"
  },
  "title" : "init(x:yStart:yEnd:width:stacking:)"
}
-->

# init(x:yStart:yEnd:width:stacking:)

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

```
nonisolated init<X>(x: PlottableValue<X>, yStart: CGFloat? = nil, yEnd: CGFloat? = nil, width: MarkDimension = .automatic, stacking: MarkStackingMethod = .standard) where X : Plottable
```

## Parameters

`x`

The value plotted with x.

`yStart`

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

`yEnd`

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

`width`

The bar width.  If `width` 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 horizontal bar:

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

![Horizontal bar chart with one bar on the x-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.BarMarkHorizontalStacked1DBarChartWithForegroundColor@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)