小编apo*_*pod的帖子

Swift Charts 不会显示带有 AxisMarks 的最后一个 x 轴 AxisValueLabel

我正在使用新的快速图表框架来显示一些数据。为了手动控制 x 轴 AxisValueLabels 的频率以及调整颜色,我实现了以下内容:

.chartXAxis {
    AxisMarks(values: .automatic(desiredCount: 11, roundLowerBound: true, roundUpperBound: true)) { _ in
        AxisGridLine(stroke: .init(lineWidth: 1)).foregroundStyle(Color.orange)
        AxisValueLabel().foregroundStyle(Color.orange).font(.subheadline).offset(x: -10)
    }
}
Run Code Online (Sandbox Code Playgroud)

我想显示每个 x 轴值的值(有 11 个点,但仅显示 10 个)。我已经尝试了无数的方法,但无法通过调整desiredCount参数来显示它应该显示的内容。将不胜感激在这件事上的任何帮助..

import Charts
import Foundation
import SwiftUI

struct FakeData: Codable {
    var questionAndAnswers: [Int: Int]
    var timePerQuestion: [Double]
    var date: Date = .now
}

extension FakeData {
    static let oneFakeInstance = FakeData(questionAndAnswers: [1875: 1875,
                                                               1890: 1890,
                                                               1980: 1980,
                                                               2112: 2112,
                                                               2726: 2726,
                                                               4088: 4088,
                                                               4284: 4284,
                                                               4784: 4784,
                                                               4800: 4800, …
Run Code Online (Sandbox Code Playgroud)

swift swiftui swiftui-charts

7
推荐指数
2
解决办法
2237
查看次数

标签 统计

swift ×1

swiftui ×1

swiftui-charts ×1