Contents

AreaPlot

Chart content that represents a function or a collection of data using the area of one or more regions.

Declaration

struct AreaPlot<Content>

Overview

Use AreaPlot when you want to visualize data in the same way as with AreaMark, but you want to plot a function or visualize an entire data collection with a single plot.

Plotting areas 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 {
    AreaPlot(
        portfolioElements,
        x: .value("Date", \.date),
        y: .value("Asset value", \.assetValue),
        series: .value("Asset", \.asset),
        stacking: .standard
    )
    .foregroundStyle(by: .value("Asset", \.asset))
}

Plotting functions

In addition to providing data points, you can provide a function to an AreaPlot to plot a function. For example, you can plot the area between y = x and y = x^2 - 1 with:

Chart {
    AreaPlot(x: "x", yStart: "x", yEnd: "x^2 - 1") { x in (yStart: x, yEnd: x * x - 1) }
}
.chartXScale(domain: -2 ... 2)
.chartYScale(domain: -4 ... 4)

You can also provide a single function to an AreaPlot. In this case it will plot the area between zero and the given function.

Chart {
    AreaPlot(x: "x", y: "x^2 - 1") { x in x * x - 1 }
}
.chartXScale(domain: -2 ... 2)
.chartYScale(domain: -4 ... 4)

Topics

Plotting areas from a collection

Plotting functions

Supporting types

See Also

Vectorized plots