I am trying to build a Line Chart View using Swift charts in SwiftUI. I have x values from 0 to 23, and random y values between 30 and 40, however the plot is covering the whole screen and I just need the portion from 30 to 40 on the y-axis. What should I do? The code:
struct PatientData: Decodable, Encodable, Identifiable {
var id: Int?
let temperature: Double
let timestamp: Int
init(id: Int, temperature: Double, timestamp: Int) {
self.id = id
self.temperature = temperature
self.timestamp = timestamp
}
}
func generateData() -> [PatientData]{
var data: [PatientData] = []
for i in 0...23 {
data.append(
PatientData(id: i, temperature: Double.random(in: 30.0...40.0), timestamp: i)
)
}
return data
}
struct TemperatureChartView: View {
var data = generateData()
var body: some View {
Chart (data){
LineMark(x: .value("Time", $0.timestamp), y: .value("Temperature", $0.temperature))
}
}
}
struct TemperatureChartView_Previews: PreviewProvider {
static var previews: some View {
TemperatureChartView()
}
}