我在swift 3.0 xcodeproject中使用iOS Charts.framework(https://github.com/danielgindi/Charts)。
我知道“所有数据集构造函数都已更改 - 它们不再采用x-indices数组”但如果LineChartData不再具有“xVals”参数,如何在x轴上放置字符串? ? 之前很容易做到......
let weights: [Double] = self.getWeigths()
let weightDates: [String] = self.getWeightDates()
var yValues : [ChartDataEntry] = [ChartDataEntry]()
for i in 0 ..< dateLastWeights.count {
let entry = ChartDataEntry(x: Double(i), y: weights[i])
yValues.append(entry)
}
let set: LineChartDataSet = LineChartDataSet(values: yValues, label: "First Set")
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
dataSets.append(set)
let data: LineChartData = LineChartData(xVals: weightDates, dataSets: dataSets)
答案 0 :(得分:1)
在尝试了很多事情并与其他开发人员讨论之后我们就成功了!
self.lineChart.xAxis.granularity = 1
self.lineChart.xAxis.valueFormatter = DefaultAxisValueFormatter(block: { (index, _) -> String in
return self.dateLastWeights[Int(index)]
})
答案 1 :(得分:1)
从3.0.1版开始,你也可以这样做:
lineChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: labels)
lineChart.xAxis.granularity = 1.0