For example, I would like to plot every 10th point of the arrays "xData" and "yData". I have tried playing around with "index", but recieve an error stating that "index" is immutable. Another approach I tried was to create two new data arrays decremented by the approprate value (i.e., use verey 10th element) , but that seems messy.
Data arrays defined as follows:
public let xData = [499.9,500.9,501.9,502.9,503.9,504.9,505.9,506.9,507.9,508.9,509.9,510.9,511.9,512.9,513.9,514.9,515.9...]
public let yData = [104.59,104.17,103.76,103.34,102.93,102.51,102.1,101.68,101.27,100.86,100.45,100.04,99.633,99.225,98.818...]
Swiftui code that renders a LineMark plot:
import SwiftUI
import Charts
struct ContentView: View {
var body: some View {
NavigationStack {
Chart(0..<xData.count, id: \.self) { index in
LineMark(
x: .value("X-Axis", xData[index]),
y: .value("Y-Axis", yData[index]) )
}
.chartXAxisLabel(position: .bottom, alignment: .center)
{ Text("X-Axis")
.font(.system(size: 14)) }
.chartYAxisLabel(position: .leading, alignment: .center)
{ Text("Y-Axis")
.font(.system(size: 14))
.rotationEffect(Angle(degrees: 180))
.frame(width: 75, height: 75)
}
.chartYAxis {
AxisMarks(position: .leading)
}
.padding()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Thank you in advance!