Код: Выделить всё
struct BestWeights: Identifiable
{
let id = UUID()
let date: String
let maxWeight: Int
}
Код: Выделить всё
private var bestWeights: [BestWeights] {
let unformattedMonth = DateFormatter().monthSymbols[month - 1]
let formattedMonth = String(unformattedMonth.prefix(3))
bestWeights.append(BestWeights(date: formattedMonth, maxWeight: bestWeightOfPeriod))
//decrementing down one month
selectedDate = Calendar.current.date(byAdding: .month, value: -1, to: selectedDate) ?? selectedDate
}
Код: Выделить всё
Chart {
ForEach(bestWeights) { bestWeight in
LineMark(x: .value("Date",bestWeight.date), y: .value("MaxWeight", bestWeight.maxWeight))
.symbol {
Circle()
.fill(.blue)
.frame(width: 7, height: 7)
}
}
}

Это не то, чего я хочу. Я не хочу, чтобы 0 отображались на оси Y. Поэтому я добавил проверку, чтобы не добавлять bestWeight с весом, равным 0:
Код: Выделить всё
if(bestWeightOfPeriod != 0) {
bestWeights.append(BestWeights(date: formattedMonth, maxWeight: bestWeightOfPeriod))
}
Как мне пометить недостающие месяцы?

Мне нужна ось Y второе изображение, а не ось X первого изображения.
Подробнее здесь: https://stackoverflow.com/questions/788 ... ftui-chart
Мобильная версия