ChartsOrg / ChartsOrg/Charts

Enable highlight per drag on zoomed in chart

Open
#4,639 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I am using the Charts library in Swift for a line graph that I want to highlight on drag, enable zoom, and highlight on drag while zoomed in. The latter is the one giving me an issue as highlightPerDragEnabled only works when the graph is zoomed out completely. By default, no highlight takes place when the graph is zoomed in and any dragging gesture just moves the actual graph.

As a workaround, I tried adding a UILongPressGestureRecognizer to the line graph and monitored the .began/.ended state to disable/enable scrolling on the graph, hoping this would allow the graph to highlight since the graph would be forced to remain in place. This did not work. All my attempt did was disable the graph from scrolling after the gesture was initiated, but no highlighting took place on drag even though the graph was not allowed to scroll.

Am I approaching this incorrectly? Has anyone tried to accomplish something similar and been successful with their approach? I appreciate your help in advance. I have attached my attempt below for clarification.

```
@objc func handleLongPress(sender:UILongPressGestureRecognizer) {

if (sender.state == UIGestureRecognizer.State.ended) {
lineChartView.dragEnabled = true
} else if (sender.state == UIGestureRecognizer.State.began) {
lineChartView.dragEnabled = false
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.