📊

SwiftChartsの .value()の第一引数が使われる様子

2025/02/08に公開

SwiftChartsの .value() の第一引数が何に使われるかよくわからなかったので確かめました。

https://youtu.be/NK3CiCnfJI0

import SwiftUI
import Charts

struct ContentView: View {
    
    struct A: Identifiable {
        var id: String {
            name
        }
        let name: String
        let score: Int
    }
    let subjects: [A] = [
        A(name: "Suzuki", score: 3),
        A(name: "Sato", score: 4),
        A(name: "Takahashi", score: 5)]
    
    var body: some View {
        Chart(subjects, id: \.name) { element in
            BarMark(
                x: .value("name", element.name),
                y: .value("score", element.score)
            )
        }
        .frame(height: 200.0)
        .padding()
    }
}

操作は VoiceOverをOnにして

  1. 左の要素を選択
  2. 中央の要素を選択
  3. 右の要素を選択
  4. Chartの詳細を読み上げ

です。

the X axis is name
the Y axis is score
there's one data series

と読み上げています。(冠詞の間違いなどがあるかもしれませんが。)

Voice Overの操作
https://youtu.be/qHnVSQkv8vQ?feature=shared&t=889

Discussion