我在图书馆搜索了两天,不幸的是我无法找到如何在 px 中获取两个数据之间的空间。Mylinechartview
包含在 aUIScrollView
中,目的是获取linechartview
位于 中心的点的值ScrollView
。
问问题
1962 次
2 回答
1
通常,它有一个转换器将数据值转换为 px 值,例如:
position.x = CGFloat(i) // index on x axis, like 0,1,2
position.y = 0.0
position = CGPointApplyAffineTransform(position, valueToPixelMatrix)
上面的代码取自internal func drawLabels
,你应该看看
在这个位置之后将是 px。屏幕上的价值。您只需要弄清楚如何获取它并将其传递给您的其他功能,例如使用委托
于 2015-11-13T01:27:58.057 回答
1
使用https://github.com/danielgindi/Charts时
你可以通过:
let yAxis: Double = 1000 // your value on y-Axis
let xAxis: Double = 5 // your value on x-Axis
let pixel: CGPoint = yourChartView.pixelForValues(x: xAxis, y: yAxis, axis: .right)
或者
let yourDataArray = [ChartDataEntry]()
//... some code here for filling data
//now, get then position
if let lastPosition = yourDataArray.last {
let point:CGPoint = yourChartView.getPosition(entry: , axis: .right)
}
此外,您可以查看https://github.com/danielgindi/Charts/blob/master/Source/Charts/Utils/Transformer.swift使用:
let valueToPixelMatrix = yourChartView.getTransformer(forAxis: YAxis.AxisDependency.right).valueToPixelMatrix
于 2020-12-25T13:23:02.310 回答