I am utilizing Swift Charts in a SwiftUI app to create a line chart. Nonetheless, with my present information, I am experiencing further house between the Y-axis and the primary LineMark level. I would love the LineMark to begin straight from the Y-axis. I might additionally like the identical adjustment on the finish.
struct ChartView: View {
let information = [ChartData(day: "Monday", value: 2),
ChartData(day: "Tuesday", value: 2.5),
ChartData(day: "Wednesday", value: 2.45),
ChartData(day: "Thursday", value: 1.76),
ChartData(day: "Friday", value: 2),
ChartData(day: "Saturday", value: 15.3),
ChartData(day: "Sunday", value: 2.4)]
let linearGradient = LinearGradient(gradient: Gradient(colours: [Color.accentColor.opacity(0.4),
Color.accentColor.opacity(0.2)]),
startPoint: .prime,
endPoint: .backside)
var selectedMaeker: Double = 2.0
var physique: some View {
Chart {
ForEach(information) { worth in
AreaMark(x: .worth("Days", worth.day),
y: .worth("Values", worth.worth))
.alignsMarkStylesWithPlotArea()
.interpolationMethod(.linear)
.foregroundStyle(linearGradient)
LineMark(x: .worth("12 months", worth.day),
y: .worth("Inhabitants", worth.worth))
.interpolationMethod(.linear)
PointMark(x: .worth("12 months", worth.day),
y: .worth("Inhabitants", worth.worth))
.interpolationMethod(.linear)
.annotation(place: .overlay, alignment: .bottomTrailing, spacing: 10) {
if selectedMaeker == worth.worth {
Textual content("T")
}
}
}
.interpolationMethod(.linear)
}
.body(width: 400, top: 300)
.chartYAxis {
AxisMarks(place: .main)
}
.chartXAxisLabel(place: .backside, alignment: .middle) {
Textual content("x title")
}
.chartYAxisLabel(place: .main, alignment: .middle) {
}
.padding(10)
}
}