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

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

Creates a bar mark that plots values with x and y.

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

## Parameters

`x`

The value plotted with x.

`y`

The value plotted with y.

`width`

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

`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 one or more bars.  For horizontal bars, plot categories or dates with y and numbers with x. For vertical bars,
plot categories or dates with x and numbers with y:

```swift
Chart(data) {
    BarMark(
        x: .value("Department", $0.department),
        y: .value("Profit", $0.profit)
    )
}
```

![Vertical bar chart with x-axis showing department categories Production, Marketing, Finance and with y-axis ranging from 0 to 15000. There are 3 bars: Production 15000, Marketing 8000, Finance 10000.](images/com.apple.Charts/BarMarkSwift.BarMarkBarChart@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)