gpt4 book ai didi

ios - Swift Charts : . chartYScale 似乎只能以 100 为增量工作?

转载 作者:行者123 更新时间:2023-12-05 01:50:39 28 4
gpt4 key购买 nike

鉴于这是一个心率图表,我正在尝试使图表的 Y 最大刻度为 210 (bpm),例如.chartYScale(domain: 0 ... 210) 但是,如果我传入 200 或 300,它似乎只能正确缩放,介于两者之间的任何值都不起作用。这是有意为之还是错误?

import SwiftUI
import Charts
import HealthKit

struct TestYAxisRangeChart: View {

let heartRateData = [80.0, 90.0, 120.0, 150.0, 160.0, 140.0, 125.0, 110.0, 88.0]

var body: some View {
Chart {
ForEach(heartRateData, id: \.self) { sample in
LineMark(
x: .value("", heartRateData.firstIndex(of: sample)!),
y: .value("HR", sample))
.foregroundStyle(Color.red)

}

}
.chartYAxis{
AxisMarks(position: .leading)
}
.frame(height: 300)
.padding(.horizontal)
.chartYScale(domain: 0 ... 210)
}

}

struct TestYAxisRangeChart_Previews: PreviewProvider {
static var previews: some View {
TestYAxisRangeChart()
}
}

最佳答案

也许您只需要这个(Xcode 14b4/iOS 16):

let yValues = stride(from: 0, to: 220, by: 10).map { $0 } // << here !!

var body: some View {
Chart {
ForEach(heartRateData, id: \.self) { sample in
LineMark(
x: .value("", heartRateData.firstIndex(of: sample)!),
y: .value("HR", sample))
.foregroundStyle(Color.red)

}

}
.chartYAxis{
AxisMarks(position: .leading, values: yValues) // << here !!
}

demo

Test module on GitHub

关于ios - Swift Charts : . chartYScale 似乎只能以 100 为增量工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72902333/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com