【发布时间】:2019-09-11 18:27:00
【问题描述】:
我正在使用以下库在我的 iOS 应用中实现图表: https://github.com/danielgindi/Charts
在 xAxis 上,我希望使用类似于屏幕截图中的格式。 我想显示一次月份的名称,然后是该月的几天(没有月份名称),当月份发生变化时,再次显示名称。
xAxis 配置的当前代码,显示每个条目的月份和日期:
xAxis.drawAxisLineEnabled = true
xAxis.drawGridLinesEnabled = false
xAxis.centerAxisLabelsEnabled = true
xAxis.drawLabelsEnabled = true
xAxis.axisLineColor = R.Color.Chart.Alpha.separator
xAxis.labelTextColor = R.Color.Chart.Alpha.content
xAxis.labelPosition = .bottom
xAxis.labelCount = 5
xAxis.valueFormatter = XAxisValueFormatter()
class XAxisValueFormatter: AxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
let date = Date(timeIntervalSince1970: value)
return date.to(DateFormat.monthday)
}
}
【问题讨论】:
-
您能否编写一些代码来配置 X 轴的日期?
-
@CodeChanger 我已经用我当前的实现更新了代码。
标签: ios-charts