gpt4 book ai didi

swift - 使用图表 UI 时如何获取突出显示点的 x 值?

转载 作者:行者123 更新时间:2023-11-30 10:37:19 25 4
gpt4 key购买 nike

我有一个变量,该变量根据用户在图表上定义的点的 x 值而变化。我该怎么办?我需要该点的 x 坐标才能更改另一个 View 。

现在,我有一个简单的组合图表。我想要的是当一个点突出显示时,然后获得 x 坐标,这会更改标签。 (例如,如果用户点击(1,3),标签将显示“1”

我已经尝试过:

Global.chiller1x = Double(chiller1Chart.xAxis.labelPosition.rawValue)
print(String(format: "%.2f", Global.chiller1x ?? 0))

我也查看了 getMarkerPosition 等,但似乎没有一个起作用。

最佳答案

您可以使用图表委托(delegate) (ChartViewDelegate) 方法 chartValueSelected() 来捕获用户点击该触摸点上的 X 和 Y 值。

使用以下方法:

extension LineChartViewController: ChartViewDelegate{
public func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
//Print Value like entry.x & entry.y
}
}

希望这能帮助您让用户了解 X 和 Y 值。

关于swift - 使用图表 UI 时如何获取突出显示点的 x 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57687192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com