ChartProxy
A proxy that you use to access the scales and plot area of a chart.
Declaration
struct ChartProxyOverview
You get a chart proxy from the chartOverlay(alignment:content:) and 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)")
}
)
}
}Topics
Instance Properties
Instance Methods
angle(at:)foregroundStyle(for:)foregroundStyleDomain(dataType:)lineStyle(for:)lineStyleDomain(dataType:)position(for:)position(forX:)position(forY:)positionRange(for:)positionRange(forX:)positionRange(forY:)selectAngleValue(at:)selectXRange(from:to:)selectXValue(at:)selectYRange(from:to:)selectYValue(at:)symbol(for:)symbolDomain(dataType:)symbolSize(for:)symbolSizeDomain(dataType:)value(at:as:)value(atAngle:as:)value(atX:as:)value(atY:as:)xDomain(dataType:)yDomain(dataType:)