<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Charts",
  "identifier" : "/documentation/Charts/LinePlot",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift Charts"
    ],
    "preciseIdentifier" : "s:6Charts8LinePlotV"
  },
  "title" : "LinePlot"
}
-->

# LinePlot

Chart content that represents a function or a collection of data using a sequence of connected line segments.

```
struct LinePlot<Content>
```

## Overview

Use `LinePlot` when you want to visualize data in the same way as with [`LineMark`](/documentation/Charts/LineMark),
but you want to plot a function or visualize an entire data collection with a single plot.

### Plotting lines from a collection

You can initialize and style the plot with simple values or key paths.
Add modifiers with `KeyPath` before adding modifiers with simple values.

```
Chart {
    LinePlot(
        stocks,
        x: .value("Date", \.date),
        y: .value("Price", \.price),
        series: .value("Asset", \.symbol)
    )
    .foregroundStyle(by: .value("Asset", \.symbol))
}
```

### Plotting functions

In addition to providing data points, you can provide a function to a `LinePlot` to plot a function.
For example, you can plot the function y = x^2 with:

```
Chart {
    LinePlot(x: "x", y: "y") { x in x * x }
}
.chartXScale(domain: -10 ... 10)
.chartYScale(domain: -10 ... 10)
```

You can add multiple function plots in a chart and use different foreground
styles to distinguish among them.

```
Chart {
    LinePlot(x: "x", y: "y = sin(x)") { sin($0) }
        .foregroundStyle(by: .value("expression", "y=sin(x)"))
        .lineStyle(StrokeStyle(lineWidth: 5, lineCap: .round))
        .opacity(0.8)

    LinePlot(x: "x", y: "y = cos(x)") { cos($0) }
        .foregroundStyle(by: .value("expression", "y=cos(x)"))
        .lineStyle(StrokeStyle(lineWidth: 5, lineCap: .round))
        .opacity(0.8)
}
.chartXScale(domain: -10 ... 10)
.chartYScale(domain: -10 ... 10)
```

You can plot a parametric function with the constructor with `x`, `y`, and `t`:

```
Chart {
    LinePlot(x: "x", y: "y", t: "t", domain: 0 ... .pi * 2) {
        t in (x: 10 * cos(5 * t) * cos(t), y: 10 * cos(5 * t) * sin(t))
    }
}
.chartXScale(domain: -10 ... 10)
.chartYScale(domain: -10 ... 10)
```

## Topics

### Plotting lines from a collection

[`init(_:x:y:)`](/documentation/Charts/LinePlot/init(_:x:y:))

[`init(_:x:y:series:)`](/documentation/Charts/LinePlot/init(_:x:y:series:))

### Plotting functions

[`init(x:y:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:domain:function:)-6m9gg)

Creates a mark that graphs a function y = f(x).

[`init(x:y:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:domain:function:)-1135f)

Creates a mark that graphs a function y = f(x).

[`init(x:y:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:domain:function:)-17i43)

Creates a mark that graphs a function y = f(x).

[`init(x:y:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:domain:function:)-6gv5v)

Creates a mark that graphs a function y = f(x).

### Plotting parametric functions

[`init(x:y:t:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:t:domain:function:)-5c4bo)

Creates a mark that graphs a parametric function (x, y) = f(t).

[`init(x:y:t:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:t:domain:function:)-7bvyi)

Creates a mark that graphs a parametric function (x, y) = f(t).

[`init(x:y:t:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:t:domain:function:)-610ta)

Creates a mark that graphs a parametric function (x, y) = f(t).

[`init(x:y:t:domain:function:)`](/documentation/Charts/LinePlot/init(x:y:t:domain:function:)-3mqls)

Creates a mark that graphs a parametric function (x, y) = f(t).

### Supporting types

[`body`](/documentation/Charts/ChartContent/body-swift.property)

The content and behavior of the chart content.

[`VectorizedLinePlotContent`](/documentation/Charts/VectorizedLinePlotContent)

An opaque vectorized chart content type.

[`FunctionLinePlotContent`](/documentation/Charts/FunctionLinePlotContent)



---

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)