I am trying to create a SwiftUI
chart that doesn’t start its y-axis at 0. This is the current issue – see screenshot below. Even though first data in stockPrices
is 132.70
the chart starts at 0.
I am aware of this question, but if I add .chartYScale(domain: .automatic(includesZero: false))
it doesn’t do anything.
See code here
let stockPrices = [
StockPrice(timestamp: "2024-04-01 09:30:00", price: 132.70),
StockPrice(timestamp: "2024-04-02 09:30:00", price: 126.10),
StockPrice(timestamp: "2024-04-03 09:30:00", price: 140.60),
.... nothing lower than 120
]
Chart(stockPrices) {
AreaMark(
x: .value("Month", $0.timestamp),
y: .value("Total", $0.price)
)
}
.chartYScale(domain: .automatic(includesZero: false))
Just to be aware as a little difficult to see – the values on y-axis are 150
, 100
, 50
.