我能够为一个特定的月份(即二月)生成 X 轴。
func generateDateAxisValues(_ month: Int, year: Int) -> [ChartAxisValueDate] {
let date = dateWithComponents(1, month, year)
let calendar = Calendar.current
let monthDays = calendar.range(of: .day, in: .month, for: date)!
let arr = CountableRange<Int>(monthDays)
return arr.map {day in
let date = dateWithComponents(day, month, year)
let axisValue = ChartAxisValueDate(date: date, formatter: displayFormatter, labelSettings: labelSettings)
axisValue.hidden = !(day % 5 == 0)
return axisValue
}
}
但我想在过去 30 天内拉伸 X 轴值;不只是一个月。如何生成过去 30 天的 X 轴值?