One Logo Pool Ball
Charts · IOS API REFERENCE

ChartProxy

struct · iOS 16.0+ · SDK 27.1

struct ChartProxy

A proxy that you use to access the scales and plot area of a chart. You get a chart proxy from the <doc://com.apple.documentation/documentation/SwiftUI/View/chartOverlay(alignment:content:)> and <doc://com.apple.documentation/documentation/SwiftUI/View/chartBackground(alignment:content:)> modifiers. You can use the chart proxy to convert data values to screen coordinates or vice-versa. Below is an example where we convert the screen coordinates from a drag gesture to data values. ``` Chart(data) { LineMark( x: .value("date", $0.date), y: .value("price", $0.price) ) } .chartOverlay { proxy in GeometryReader { geometry in Rectangle().fill(.clear).contentShape(Rectangle()) .gesture( DragGesture() .onChanged { value in // Convert the gesture location to the coordinate space of the plot area. let origin = geometry[proxy.plotAreaFrame].origin let location = CGPoint( x: value.location.x - origin.x, y: value.location.y - origin.y ) // Get the x (date) and y (price) value from the location. let (date, price) = proxy.value(at: location, as: (Date, Double).self) print("Location: \(date), \(price)") } ) } } ```

Members (31)

method · iOS 16.4+

symbolSize

TypeScript
symbolSize(value: number): (number) | null
Swift declaration
func symbolSize<P>(for value: P) -> CGFloat? where P : Plottable

Returns the symbol size for the given data value. Returns `nil` if the symbol size scale is unavailable, or the value is invalid. - Parameter value: The data value. - Returns: The symbol size corresponding to the data value, or `nil` if the data value is incompatible with the chart.

get · iOS 16.0+ · Deprecated in iOS 17.0

plotAreaSize

TypeScript
get plotAreaSize(): { width: number; height: number }
Swift declaration
var plotAreaSize: CGSize { get }

The size of the plot in the chart. The plot is the area between the x and y axes, not including the axes themselves. A chart must exist in the context of the chart proxy.

method · iOS 17.0+

selectXRange

TypeScript
selectXRange(from: number, to: number): void
Swift declaration
func selectXRange(from: CGFloat, to: CGFloat)
method · iOS 17.0+

selectXValue

TypeScript
selectXValue(xPosition: number): void
Swift declaration
func selectXValue(at xPosition: CGFloat)
method · iOS 17.0+

selectYRange

TypeScript
selectYRange(from: number, to: number): void
Swift declaration
func selectYRange(from: CGFloat, to: CGFloat)
method · iOS 17.0+

selectYValue

TypeScript
selectYValue(yPosition: number): void
Swift declaration
func selectYValue(at yPosition: CGFloat)
method · iOS 16.4+

symbolDomain

TypeScript
symbolDomain(dataType: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): Array<unknown>
Swift declaration
func symbolDomain<P>(dataType: P.Type) -> [P] where P : Plottable
get · iOS 16.0+ · Deprecated in iOS 17.0

plotAreaFrame

TypeScript
get plotAreaFrame(): _SwiftUICore_Anchor<{ x: number; y: number; width: number; height: number }>
Swift declaration
var plotAreaFrame: Anchor<CGRect> { get }

An anchor to the frame of the chart's plot. The plot is the area between the x and y axes, not including the axes themselves. If the chart is scrollable, the plot frame includes both visible and invisible portions of the plot. A chart must exist in the context of the chart proxy. You can convert the anchor to a frame using a `GeometryProxy`.

method · iOS 16.0+

positionRange

TypeScript
positionRangeFor(point: { "x": number; "y": number }): ({ x: number; y: number; width: number; height: number }) | null
Swift declaration
func positionRange<X, Y>(for point: (x: X, y: Y)) -> CGRect? where X : Plottable, Y : Plottable

Returns the range of x and y positions for the given pair of data values, or `nil` if the y scale is unavailable or if the value is invalid. For a continuous data value, the returned range is a single point. For a categorical data value, the returned range is the range of positions that correspond to the given category. - Parameter value: The data value. - Returns: The position range corresponding to the data values.

method · iOS 16.0+

positionRange

TypeScript
positionRangeForX(value: number): ("animatableData" | SDKHandle) | null
Swift declaration
func positionRange<P>(forX value: P) -> ClosedRange<CGFloat>? where P : Plottable

Returns the range of x position for the given data value, or `nil` if the x scale is unavailable or if the value is invalid. The returned position range is relative to the plot. For a continuous data value, the returned range is a single point. For a categorical data value, the returned range is the range of positions that correspond to the given category. - Parameter value: The data value. - Returns: The position range corresponding to the data value.

method · iOS 16.0+

positionRange

TypeScript
positionRangeForY(value: number): ("animatableData" | SDKHandle) | null
Swift declaration
func positionRange<P>(forY value: P) -> ClosedRange<CGFloat>? where P : Plottable

Returns the range of y position for the given data value, or `nil` if the x scale is unavailable or if the value is invalid. The returned position range is relative to the plot. For a continuous data value, the returned range is a single point. For a categorical data value, the returned range is the range of positions that correspond to the given category. - Parameter value: The data value. - Returns: The position range corresponding to the data value.

method · iOS 16.4+

foregroundStyle

TypeScript
foregroundStyle(value: number): (_SwiftUICore_AnyShapeStyle) | null
Swift declaration
func foregroundStyle<P>(for value: P) -> AnyShapeStyle? where P : Plottable

Returns the foreground style for the given data value. Returns `nil` if the foreground style scale is unavailable, or the value is invalid. - Parameter value: The data value. - Returns: The foreground style corresponding to the data value, or `nil` if the data value is incompatible with the chart.

method · iOS 16.4+

lineStyleDomain

TypeScript
lineStyleDomain(dataType: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): Array<unknown>
Swift declaration
func lineStyleDomain<P>(dataType: P.Type) -> [P] where P : Plottable
method · iOS 17.0+

selectAngleValue

TypeScript
selectAngleValue(angle: _SwiftUICore_Angle): void
Swift declaration
func selectAngleValue(at angle: Angle)
method · iOS 16.4+

symbolSizeDomain

TypeScript
symbolSizeDomain(dataType: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): Array<unknown>
Swift declaration
func symbolSizeDomain<P>(dataType: P.Type) -> [P] where P : Plottable
get · iOS 17.0+

plotContainerFrame

TypeScript
get plotContainerFrame(): (_SwiftUICore_Anchor<{ x: number; y: number; width: number; height: number }>) | null
Swift declaration
var plotContainerFrame: Anchor<CGRect>? { get }

An anchor to the frame of the chart's plot container, or `nil` if there is no chart in the context of the chart proxy. The plot is the area between the x and y axes, not including the axes themselves. If the chart is scrollable, the plot container frame only includes the visible portion of the plot. Otherwise, it is the same as ``plotFrame``. You can convert the anchor to a frame using a `GeometryProxy`. Below is an example adding a border to the plot container: ``` Chart { ... } .chartOverlay { chartProxy in GeometryReader { geometryProxy in // Get the plot container's frame in the GeometryReader's coordinate space. // This frame stays the same when the chart scrolls. // In this example, we add a border to the plot container by stroking the frame. if let plotContainerFrame = chartProxy.plotContainerFrame { Path(geometryProxy[plotContainerFrame]) .stroke(.black, lineWidth: 1) .allowsHitTesting(false) } } } ```

method · iOS 16.4+

foregroundStyleDomain

TypeScript
foregroundStyleDomain(dataType: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): Array<unknown>
Swift declaration
func foregroundStyleDomain<P>(dataType: P.Type) -> [P] where P : Plottable
method · iOS 17.0+

angle

TypeScript
angle(position: { x: number; y: number }): _SwiftUICore_Angle
Swift declaration
func angle(at position: CGPoint) -> Angle

Returns the angle relative to the plot area center, where the 12 o'clock position is interpreted as zero degrees, increasing clockwise. - Parameter position: The position at which to obtain the data value. It should be relative to the plot. - Returns: The angle relative to the plot area center.

method · iOS 16.0+

value

TypeScript
valueAt(position: { x: number; y: number }): ([number, number]) | null
Swift declaration
func value<X, Y>(at position: CGPoint, as: (X, Y).Type = (X, Y).self) -> (X, Y)? where X : Plottable, Y : Plottable

Returns the data values at the given position, or `nil` if the position does not correspond to a valid Y value. - Parameter position: The position at which to obtain the data values. It should be relative to the plot. - Returns: A tuple of the x and y data values at the given position.

method · iOS 16.0+

value

TypeScript
valueAtXAs(position: number, as?: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): (unknown) | null
Swift declaration
func value<P>(atX position: CGFloat, as: P.Type = P.self) -> P? where P : Plottable

Returns the data value at the given x position, or `nil` if the position does not correspond to a valid X value. - Parameter position: The position at which to obtain the x data value. It should be relative to the plot. - Returns: The data value at the given position.

method · iOS 16.0+

value

TypeScript
valueAtYAs(position: number, as?: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): (unknown) | null
Swift declaration
func value<P>(atY position: CGFloat, as: P.Type = P.self) -> P? where P : Plottable

Returns the data value at the given y position, or `nil` if the position does not correspond to a valid Y value. - Parameter position: The position at which to obtain the y data value. It should be relative to the plot. - Returns: The data value at the given position.

method · iOS 17.0+

value

TypeScript
valueAtAngleAs(angle: _SwiftUICore_Angle, as?: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): (unknown) | null
Swift declaration
func value<P>(atAngle angle: Angle, as: P.Type = P.self) -> P? where P : Plottable

Returns the data value at the given angle, or `nil` if the angle does not correspond to a valid data value. - Parameter angle: The angle, relative to the plot center, where the 12 o'clock position is interpreted as zero degrees, increasing clockwise. - Returns: The data value at the given position.

method · iOS 16.4+

symbol

TypeScript
symbol(value: number): (AnyChartSymbolShape) | null
Swift declaration
func symbol<P>(for value: P) -> AnyChartSymbolShape? where P : Plottable

Returns the symbol for the given data value. Returns `nil` if the symbol scale is unavailable, or the value is invalid. - Parameter value: The data value. - Returns: The symbol corresponding to the data value, or `nil` if the data value is incompatible with the chart.

method · iOS 16.4+

xDomain

TypeScript
xDomain(dataType: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): Array<unknown>
Swift declaration
func xDomain<P>(dataType: P.Type) -> [P] where P : Plottable
method · iOS 16.4+

yDomain

TypeScript
yDomain(dataType: "Int" | "UInt" | "Double" | "Float" | "String" | "Date" | "Foundation.Decimal"): Array<unknown>
Swift declaration
func yDomain<P>(dataType: P.Type) -> [P] where P : Plottable
get · iOS 17.0+

plotSize

TypeScript
get plotSize(): { width: number; height: number }
Swift declaration
var plotSize: CGSize { get }

The size of the plot in the chart. The plot is the area between the x and y axes, not including the axes themselves.

method · iOS 16.0+

position

TypeScript
positionFor(point: { "x": number; "y": number }): ({ x: number; y: number }) | null
Swift declaration
func position<X, Y>(for point: (x: X, y: Y)) -> CGPoint? where X : Plottable, Y : Plottable

Returns the x and y positions as a `CGPoint` for the given data values, or `nil` if either the X or the y scale is unavailable or if any data value is invalid. The returned position is relative to the plot. - Parameter point: A tuple of x and y data values. - Returns: The position corresponding to the data values.

method · iOS 16.0+

position

TypeScript
positionForX(value: number): (number) | null
Swift declaration
func position<P>(forX value: P) -> CGFloat? where P : Plottable

Returns the x position for the given data value, or `nil` if the x scale is unavailable or if the data value is invalid. The returned position is relative to the plot. - Parameter value: A data value. - Returns: The position corresponding to the data value.

method · iOS 16.0+

position

TypeScript
positionForY(value: number): (number) | null
Swift declaration
func position<P>(forY value: P) -> CGFloat? where P : Plottable

Returns the y position for the given data value, or `nil` if the y scale is unavailable or if the data value is invalid. The returned position is relative to the plot. - Parameter value: A data value. - Returns: The position corresponding to the data value.

method · iOS 16.4+

lineStyle

TypeScript
lineStyle(value: number): (_SwiftUICore_StrokeStyle) | null
Swift declaration
func lineStyle<P>(for value: P) -> StrokeStyle? where P : Plottable

Returns the line style for the given data value. Returns `nil` if the line style scale is unavailable, or the value is invalid. - Parameter value: The data value. - Returns: The line style corresponding to the data value, or `nil` if the data value is incompatible with the chart.

get · iOS 17.0+

plotFrame

TypeScript
get plotFrame(): (_SwiftUICore_Anchor<{ x: number; y: number; width: number; height: number }>) | null
Swift declaration
var plotFrame: Anchor<CGRect>? { get }

An anchor to the frame of the chart's plot, or `nil` if there is no chart in the context of the chart proxy. The plot is the area between the x and y axes, not including the axes themselves. If the chart is scrollable, the plot frame includes both visible and invisible portions of the plot. You can convert the anchor to a frame using a `GeometryProxy`.

Skipped declarations

No declarations were skipped in this snapshot.

All Charts types →