我正在使用 Daniel Gindi 的Swift Charts库。我试图在散点图中显示每个点的单独值。
我已将集合的 drawValuesEnabled 设置为 true,并创建了一个自定义 IValueFormatter。然而,格式化程序类中的方法似乎从未被调用过,也没有显示任何标签。还有什么可能是造成这种情况的原因?
编辑:创建散点图的代码如下:
let graphView: ScatterChartView = {
let scatter = ScatterChartView()
scatter.translatesAutoresizingMaskIntoConstraints = false
scatter.chartDescription?.enabled = true
scatter.dragEnabled = true
scatter.setScaleEnabled(true)
//scatter.maxVisibleCount = 200
scatter.pinchZoomEnabled = false
scatter.backgroundColor = .clear
scatter.leftAxis.enabled = false
scatter.rightAxis.enabled = true
scatter.rightAxis.drawGridLinesEnabled = false
scatter.rightAxis.valueFormatter = TimeValueFormatter()
scatter.xAxis.labelPosition = XAxis.LabelPosition.bottom
scatter.xAxis.axisMaxLabels = 8
scatter.xAxis.granularity = 1
scatter.xAxis.drawLabelsEnabled = true
scatter.xAxis.drawGridLinesEnabled = false
//date formatter should be provided by controller
scatter.legend.enabled = false
return scatter
}()
数据集(x轴为整数,y轴为时间):
self.dataSet = {
let set = ScatterChartDataSet(values: entries)
set.setScatterShape(.circle)
set.setColor(UIColor.PRColors.prGreen)
set.valueFormatter = TimeValueFormatter()
return set
}()
预期结果是带有每个点显示的 y 值的标签,如示例项目中所示。