London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
6 C
New York
Friday, January 31, 2025

swift – The best way to change Y axis scale for Multi line chart in iOS utilizing SwiftUI


I’m creating multi-line chart utilizing Apple’s Chart framework in SwiftUI. In that I’ve 2 strains with totally different vary of information. So, I need to set totally different scale for each of strains. Right here is my code for identical.

struct ChartPlot: Identifiable, Hashable {
    let id: UUID = .init()
    let x: Int
    let y: Int
}

struct SwiftUIView1: View {
    let arr1 = [
        ChartPlot(x: 2, y: 1),
        ChartPlot(x: 4, y: 5),
        ChartPlot(x: 6, y: 4),
        ChartPlot(x: 8, y: 8),
        ChartPlot(x: 10, y: 7)
    ]
    let arr2 = [
        ChartPlot(x: 1, y: 20),
        ChartPlot(x: 2, y: 60),
        ChartPlot(x: 4, y: 45),
        ChartPlot(x: 7, y: 70),
        ChartPlot(x: 9, y: 40)
    ]
    var physique: some View {
        Chart {
            ForEach(arr1) { plot in
                LineMark(
                    x: .worth("", plot.x),
                    y: .worth("", plot.y),
                    collection: .worth("", "Value1"))
            }
            .foregroundStyle(.yellow)

            ForEach(arr2) { plot in
                LineMark(
                    x: .worth("", plot.x),
                    y: .worth("", plot.y),
                    collection: .worth("", "Value2"))
                .foregroundStyle(.crimson)
            }
        }
        .chartYScale(area: 0...100, kind: .linear)
        .chartYAxis {
            AxisMarks(place: .main, values: .computerized) {
                AxisValueLabel()
                    .foregroundStyle(.orange)
                AxisTick()
                    .foregroundStyle(.orange)
            }
        }
        .chartYScale(area: 0...10, kind: .linear)
        .chartYAxis {
            AxisMarks(place: .trailing, values: .computerized) {
                AxisValueLabel()
                    .foregroundStyle(.inexperienced)
                AxisTick()
                    .foregroundStyle(.inexperienced)
            }
        }
    }
}

As you may see within the knowledge, 1 set is having vary from 0 to 10 and one other having 0 to 100, So, I need to use totally different scale for each strains (orange and inexperienced).
However I am getting right code.

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com