Home IOS Development SwiftUI/iOS 17 methods to restrict measurement of scrollable Chart for Dates ? `chartXVisibleDomain(size:)` not working

SwiftUI/iOS 17 methods to restrict measurement of scrollable Chart for Dates ? `chartXVisibleDomain(size:)` not working

0
SwiftUI/iOS 17 methods to restrict measurement of scrollable Chart for Dates ? `chartXVisibleDomain(size:)` not working

[ad_1]

I need to show a SwiftUI scrollable Chart with Dates on the X axis, however I need to restrict the variety of dates seen directly on the display (solely show 7 days for example)
Chart not limited on X axis

Since iOS 17 now we have https://developer.apple.com/documentation/swiftui/view/chartscrollableaxes(_:) and https://developer.apple.com/documentation/swiftui/view/chartxvisibledomain(size:)

chartXVisibleDomain(size:) is meant to restrict the variety of objects seen, and it does work for when my X axis objects are simply Ints, however when they’re Dates, I simply get a clean display with no log/error

This works accurately:

struct GraphView: View {
    static let objects = 1...100
    var physique: some View {
        Chart {
            ForEach(Self.objects, id: .self) { i in
                PointMark(
                    x: .worth("x", i),
                    y: .worth("y", i)
                )
            }
        }
        .chartScrollableAxes(.horizontal)
        .chartXVisibleDomain(size: 10)
    }
}

However this offers a clean display:

struct GraphView: View {
    static let objects = Array(
        stride(
            from: Date.now.addingTimeInterval(-30 * 24 * 60 * 60),
            to: Date.now,
            by: 100
        )
    )
    var physique: some View {
        Chart {
            ForEach(Self.objects.indices, id: .self) { index in
                LineMark(
                    x: .worth("x", Self.objects[index], unit: .day),
                    y: .worth("y", index)
                )
            }
        }
        .chartScrollableAxes(.horizontal)
        .chartXVisibleDomain(size: 10)
    }
}

You may remark .chartScrollableAxes(.horizontal) and .chartXVisibleDomain(size: 10) and you will get a consequence, however the variety of seen objects on the X axis is not going to be restricted

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here