iOS Charts 组合图表只能通过图表函数访问部分条目

发布于 2025-01-16 21:07:37 字数 803 浏览 0 评论 0原文

随着 iOS 图表 4.0 的更新,我重做了所有图表,包括将其中的许多图表更改为 CombinedChartViews。但是,现在我在使用内置函数访问条目时遇到了一个非常奇怪的问题。

正如预期的那样,数据显示得很好,但突出显示时,只有部分值被选择。这些值与只能通过 getEntryByTouchPoint 等函数访问的值相同。

guard let valOrig = self.getEntryByTouchPoint(point: location) else { return }
guard let val = lineBaseSet?.entries.getItemAt(Int(valOrig.x)) else { return }
print(val.x)

仅适用于 40、60 等。

当我打印 lineData.first.entries 时,我得到的正确计数为 79,并且所有条目均正确且按顺序排列。只是当我不直接访问数组时,它似乎无法找到大多数条目。

完美运行的条目 = 40、60、70、75、78、79。

所有其他条目均不起作用。

这个数字顺序似乎是指数级的,但我仍然不明白这与它不工作的方式有什么关系。

我只在CombinedChartView 上测试过这个,所以不确定它是否适用于其他类型。

任何帮助将不胜感激!

编辑:抱歉,有点上下文,位置是触摸点的位置,lineBaseSet 是一个等于 lineData?.first 的自定义变量,getItemAt() 与 array[index] 相同,但它返回一个可选值,而不是致命的如果超出索引则崩溃。

With the new 4.0 update in iOS Charts, I have redone all of my charts, including changing a lot of them to CombinedChartViews. however, now I am running into a very weird issue with accessing the entries using the in-built functions.

The data is presenting fine, as expected, but when highlighting, only some of the values are selecting. These are the same values that are only accessible through functions such as getEntryByTouchPoint.

guard let valOrig = self.getEntryByTouchPoint(point: location) else { return }
guard let val = lineBaseSet?.entries.getItemAt(Int(valOrig.x)) else { return }
print(val.x)

Only works for 40, 60, etc.

When I print lineData.first.entries, I get the correct count of 79 and all the entries are correct and in order. It's just when I am not accessing the array directly it can't seem to find most of the entries.

Entries working perfectly = 40, 60, 70, 75, 78, 79.

All others are not working.

This order of numbers seems to be exponential but I still don't see how this relates to the way it's not working.

I have only tested this on a CombinedChartView so not sure if it's working on other types.

Any help would be appreciated!!

EDIT: Sorry, bit of context, location is the location of a touch point, lineBaseSet is a custom variable equal to lineData?.first, and getItemAt() is the same as array[index] but it returns an optional as opposed to fatally crashing if out of index.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁绊已千年 2025-01-23 21:07:37

好吧,这不是问题的直接答案,但我已经为其他有同样问题的人找到了解决方法。

函数“valueForTouchPoint(point:axis:)”和“getPosition(entry:axis:)”仍然按预期工作,因此使用以下代码,可以从 UIPanGestureRecognizer 的响应中找到条目和条目的位置:

let touchPoint = sender.location(ofTouch: 0, in: chartView)
let point = chartView.valueForTouchPoint(point: touchPoint, axis: .left)
selectedEntry = entries.first(where: { $0.x == round(Double(point.x)) })
chartView.getPosition(entry: selectedEntry, axis: .left)

从那里,可以使用 CAShapeLayer 创建水平线和垂直线并将其作为子层添加到图表视图中。

希望这有帮助!

Ok, this isn't a direct answer to the question but I've figured out a workaround for other people having the same issue.

The functions 'valueForTouchPoint(point:axis:)' and 'getPosition(entry:axis:)' still work as expected so using the following, the entry and location of the entry can be found from the response of a UIPanGestureRecognizer:

let touchPoint = sender.location(ofTouch: 0, in: chartView)
let point = chartView.valueForTouchPoint(point: touchPoint, axis: .left)
selectedEntry = entries.first(where: { $0.x == round(Double(point.x)) })
chartView.getPosition(entry: selectedEntry, axis: .left)

From there, it's possible to create the horizontal and vertical lines using a CAShapeLayer and adding that as a sublayer to the chartView.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文