Wednesday, November 11, 2026
HomeiOS Developmentios - Swift Charts: methods to add axis uni labels?

ios – Swift Charts: methods to add axis uni labels?

[ad_1]

I am attempting so as to add axis unit labels to a chart constructed with Swift Charts.

For instance:

import SwiftUI
import Charts

struct ContentView: View {
    
    struct ChartData: Identifiable {
        var id: Double { xVal }
        let xVal: Double
        let yVal: Double
    }
    
    let knowledge: [ChartData] = [
        .init(xVal: -5, yVal: 5),
        .init(xVal: 0, yVal: 10),
        .init(xVal: 5, yVal: 20),
    ]
    
    var physique: some View {
        Chart(knowledge) {
            LineMark(
                x: .worth("Place", $0.xVal),
                y: .worth("Peak", $0.yVal)
            )
        }
        .chartYAxis {
            AxisMarks(place: .main)
        }
    }
    
}

Chart output, with the specified labels annotated in pink:
enter image description here

How can we create axis labels like these in pink above – or in any other case add models/descriptions to our axes?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments