---
title: RuleMark
framework: charts
role: symbol
role_heading: Structure
path: charts/rulemark
---

# RuleMark

Chart content that represents data using a single horizontal or vertical rule.

## Declaration

```swift
@MainActor @preconcurrency struct RuleMark
```

## Overview

Overview You can use RuleMark to plot a horizontal or vertical rule in your chart. Show Range with Rule Marks To create a horizontal line at a y position from xStart to xEnd you use the init(xStart:xEnd:y:) or init(xStart:xEnd:y:).  To create a vertical line at an x position from yStart to yEnd you use init(x:yStart:yEnd:) or init(x:yStart:yEnd:). The example below uses the Pollen structure and the init(xStart:xEnd:y:) to map horizontal lines that span from the value of the startDate to the value of the endDate  for x positions to a pollen source property’s y position: struct Pollen {     var source: String     var startDate: Date     var endDate: Date

init(startMonth: Int, numMonths: Int, source: String) {         self.source = source         let calendar = Calendar.autoupdatingCurrent         self.startDate = calendar.date(from: DateComponents(year: 2020, month: startMonth, day: 1))!         self.endDate = calendar.date(byAdding: .month, value: numMonths, to: startDate)!     } }

var data: [Pollen] = [     Pollen(startMonth: 1, numMonths: 9, source: "Trees"),     Pollen(startMonth: 12, numMonths: 1, source: "Trees"),     Pollen(startMonth: 3, numMonths: 8, source: "Grass"),     Pollen(startMonth: 4, numMonths: 8, source: "Weeds") ]

var body: some View {     Chart(data) {         RuleMark(             xStart: .value("Start Date", $0.startDate),             xEnd: .value("End Date", $0.endDate),             y: .value("Pollen Source", $0.source)         )     } }

Annotate a chart with rule mark You can annotate a chart with horizontal or vertically spanning rules. This allows viewers to easily compare values over a range to a constant value. Use the init(xStart:xEnd:y:) initializer to represent a constant y value or init(x:yStart:yEnd:) for a constant x value. To span the plotting area of a chart with a line, omit the optional start and end parameters and plot a constant value.  The example below results in a line that spans the chart horizontally at the y position of 9000: struct DepartmentProfit {     var department: String     var profit: Double }

var data: [DepartmentProfit] = [     DepartmentProfit(department: "Production", profit: 15000),     DepartmentProfit(department: "Marketing", profit: 8000),     DepartmentProfit(department: "Finance", profit: 10000) ]

var body: some View {     Chart         ForEach(data) {             BarMark(                 x: .value("Department", $0.department),                 y: .value("Profit", $0.profit)             )         }         RuleMark(y: .value("Break Even Threshold", 9000))             .foregroundStyle(.red)     } }

RuleMark in Chart3D To plot a rule in a 3D chart, use the init(x:y:z:) initializer. The rule extends along the axis that you provide a range for, and is positioned at the single points you specify for the other two axes. important: A 3D rule mark requires one parameter to be a numeric range and the other two parameters to be single numeric values. For example, the following Chart3D shows three rule marks. Each mark extends along one axis and is fixed at 0 on the other two. Chart3D {     // A rule that extends along the x-axis     RuleMark(         x: .value("x", -0.5..<0.5),         y: .value("y", 0),         z: .value("z", 0)     )     .foregroundStyle(.red)

// A rule that extends along the y-axis     RuleMark(         x: .value("x", 0),         y: .value("y", -0.5..<0.5),         z: .value("z", 0)     )     .foregroundStyle(.green)

// A rule that extends along the z-axis     RuleMark(         x: .value("x", 0),         y: .value("y", 0),         z: .value("z", -0.5..<0.5)     )     .foregroundStyle(.blue) }

## Topics

### Initializers

- [init(x:y:z:)](charts/rulemark/init(x:y:z:).md)
- [init(x:yStart:yEnd:)](charts/rulemark/init(x:ystart:yend:)-5gy50.md)
- [init(x:yStart:yEnd:)](charts/rulemark/init(x:ystart:yend:)-6zemd.md)
- [init(x:yStart:yEnd:)](charts/rulemark/init(x:ystart:yend:)-8iusl.md)
- [init(xStart:xEnd:y:)](charts/rulemark/init(xstart:xend:y:)-27yvc.md)
- [init(xStart:xEnd:y:)](charts/rulemark/init(xstart:xend:y:)-444cp.md)
- [init(xStart:xEnd:y:)](charts/rulemark/init(xstart:xend:y:)-6jsoi.md)

## Relationships

### Conforms To

- [Chart3DContent](charts/chart3dcontent.md)
- [ChartContent](charts/chartcontent.md)
- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Marks

- [AreaMark](charts/areamark.md)
- [LineMark](charts/linemark.md)
- [PointMark](charts/pointmark.md)
- [RectangleMark](charts/rectanglemark.md)
- [BarMark](charts/barmark.md)
- [SectorMark](charts/sectormark.md)
