LinePlot
struct · iOS 18.0+ · SDK 27.1
struct LinePlot<Content>Chart content that represents a function or a collection of data using a sequence of connected line segments. 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) ```
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
11 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
LinePlot.body
This protocol needs associated types that cannot yet cross the bridge.
LinePlot.init(_:x:y:)
This declaration needs Swift generic type arguments. (no canonical witness for Data)
LinePlot.init(_:x:y:series:)
This declaration needs Swift generic type arguments. (no canonical witness for Data)
LinePlot.init(x:y:domain:function:)
callback cannot propagate synchronous failure
LinePlot.init(x:y:domain:function:)
callback cannot propagate synchronous failure
LinePlot.init(x:y:domain:function:)
callback cannot propagate synchronous failure
LinePlot.init(x:y:domain:function:)
callback cannot propagate synchronous failure
LinePlot.init(x:y:t:domain:function:)
callback cannot propagate synchronous failure
LinePlot.init(x:y:t:domain:function:)
callback cannot propagate synchronous failure
LinePlot.init(x:y:t:domain:function:)
callback cannot propagate synchronous failure
LinePlot.init(x:y:t:domain:function:)
callback cannot propagate synchronous failure