---
title: "init(x:y:width:height:stacking:)"
framework: charts
role: symbol
role_heading: Initializer
path: "charts/barmark/init(x:y:width:height:stacking:)"
---

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

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

## Declaration

```swift
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: Chart(data) {     BarMark(         x: .value("Department", $0.department),         y: .value("Profit", $0.profit)     ) }

## See Also

### Creating a bar mark

- [init(x:yStart:yEnd:width:)](charts/barmark/init(x:ystart:yend:width:).md)
- [init(xStart:xEnd:y:height:)](charts/barmark/init(xstart:xend:y:height:).md)
- [init(xStart:xEnd:yStart:yEnd:)](charts/barmark/init(xstart:xend:ystart:yend:)-98wo9.md)
- [init(xStart:xEnd:yStart:yEnd:)](charts/barmark/init(xstart:xend:ystart:yend:)-7541n.md)
- [init(x:yStart:yEnd:width:stacking:)](charts/barmark/init(x:ystart:yend:width:stacking:).md)
- [init(xStart:xEnd:y:height:stacking:)](charts/barmark/init(xstart:xend:y:height:stacking:).md)
