---
title: LinePlot
framework: charts
role: symbol
role_heading: Structure
path: charts/lineplot
---

# LinePlot

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

## Declaration

```swift
struct LinePlot<Content>
```

## Overview

Overview Use LinePlot when you want to visualize data in the same way as with 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:)](charts/lineplot/init(_:x:y:).md)
- [init(_:x:y:series:)](charts/lineplot/init(_:x:y:series:).md)

### Plotting functions

- [init(x:y:domain:function:)](charts/lineplot/init(x:y:domain:function:)-6m9gg.md)
- [init(x:y:domain:function:)](charts/lineplot/init(x:y:domain:function:)-1135f.md)
- [init(x:y:domain:function:)](charts/lineplot/init(x:y:domain:function:)-17i43.md)
- [init(x:y:domain:function:)](charts/lineplot/init(x:y:domain:function:)-6gv5v.md)

### Plotting parametric functions

- [init(x:y:t:domain:function:)](charts/lineplot/init(x:y:t:domain:function:)-5c4bo.md)
- [init(x:y:t:domain:function:)](charts/lineplot/init(x:y:t:domain:function:)-7bvyi.md)
- [init(x:y:t:domain:function:)](charts/lineplot/init(x:y:t:domain:function:)-610ta.md)
- [init(x:y:t:domain:function:)](charts/lineplot/init(x:y:t:domain:function:)-3mqls.md)

### Supporting types

- [body](charts/chartcontent/body-swift.property.md)
- [VectorizedLinePlotContent](charts/vectorizedlineplotcontent.md)
- [FunctionLinePlotContent](charts/functionlineplotcontent.md)

## Relationships

### Conforms To

- [ChartContent](charts/chartcontent.md)
- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [VectorizedChartContent](charts/vectorizedchartcontent.md)

## See Also

### Vectorized plots

- [Creating a data visualization dashboard with Swift Charts](charts/creating-a-data-visualization-dashboard-with-swift-charts.md)
- [AreaPlot](charts/areaplot.md)
- [PointPlot](charts/pointplot.md)
- [RectanglePlot](charts/rectangleplot.md)
- [RulePlot](charts/ruleplot.md)
- [BarPlot](charts/barplot.md)
- [SectorPlot](charts/sectorplot.md)
- [VectorizedChartContent](charts/vectorizedchartcontent.md)
