In Swift Charts can the x/y: .value be a double, or does it have to be an integer?
I'm generating a graph that is showing hours on the Y axis. Hours is hours + minutes (as a decimal) but it only seems to work with the integers and won't take doubles. Can I use a double or do I have to do a work around?
A sample part of the code is below:
Chart{
ForEach(sunriseSunset) {item in
LineMark(
x: .value("Date", item.sunrise),
y: .value("Sunrise", (((Calendar.current.dateComponents(components, from: item.sunrise).hour!) * 60) + (Calendar.current.dateComponents(components, from: item.sunrise).minute!)) / 60),
// y: .value("Sunrise", (((Calendar.current.dateComponents(components, from: item.sunrise).hour!)) + (Calendar.current.dateComponents(components, from: item.sunrise).minute!)) * minsdecimal),
series: .value("Date", "Sunrise")
)
.foregroundStyle(.orange)
.lineStyle(StrokeStyle(lineWidth: 2))
}
}
.frame(height: 300)
.chartYAxis {
AxisMarks(
values: [0, 6, 12, 18, 24]
)
}
}

Yes you can have doubles for the y axis values. To get doubles, you could try something like this for your
yvalues ofhours + minutes (as a decimal):You could of course have this in your
itemstruct:and call: