我正在尝试添加一个日期/字符串作为图表中的 xAxis 标签(标签之间需要有相等的空间)
我在下面做,但构造函数中的 x 只需要一个双倍。
任何想法?
for i in 0..<self.grahEntries.count {
let x1 = self.grahEntries[i].x
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYY-MM-DD HH:mm:ss"
let date = dateFormatter.date(from: x1)
print(date)
let dataEntry = ChartDataEntry(x: date, y: self.grahEntries[i].y)//HERE IS MY PROBLEM!! xAxis is only double
dataEntries.append(dataEntry)
}
let line1 = LineChartDataSet(values: dataEntries, label: "Units Consumed")
line1.colors = [NSUIColor.blue]
line1.mode = .cubicBezier
line1.cubicIntensity = 0.2
let gradient = getGradientFilling()
line1.fill = Fill.fillWithLinearGradient(gradient, angle: 90.0)
line1.drawFilledEnabled = true
let data = LineChartData()
data.addDataSet(line1)
mChart.data = data
mChart.setScaleEnabled(false)
mChart.animate(xAxisDuration: 1.5)
mChart.xAxis.valueFormatter = DateAxisValueFormatter()
mChart.xAxis.granularity = 1.0
mChart.drawGridBackgroundEnabled = false
mChart.xAxis.drawAxisLineEnabled = false
mChart.xAxis.drawGridLinesEnabled = false
mChart.leftAxis.drawAxisLineEnabled = true
mChart.leftAxis.drawGridLinesEnabled = true
mChart.rightAxis.drawAxisLineEnabled = false
mChart.rightAxis.drawGridLinesEnabled = false
mChart.legend.enabled = false
mChart.xAxis.enabled = true
mChart.leftAxis.enabled = true
mChart.rightAxis.enabled = false
mChart.xAxis.labelPosition = .bottom
mChart.xAxis.drawLabelsEnabled = true
mChart.xAxis.drawLimitLinesBehindDataEnabled = true
mChart.xAxis.avoidFirstLastClippingEnabled = true
更新 :