Search code examples
iosswiftlinechartios-charts

ios-charts LineChartView. How to select part of the chart


what I want to do is the following. I have a linechart with some data points on it. I want to allow user to select chunk of the chart and highlight it by dragging a finger.

I tried a few hacky approaches using ChartTransformer and tracking pixels of the UIPanGestureRecognizer and then programmatically highlighting the appropriate xIndexes, but it looks terrible.

I was wondering if there is a better way to do it. Thank you.


Solution

  • I would say your approaches should be right, what you mean it looks terrible?

    I would check when the pan gesture ended, I will calculate how many xIndex has been chosen, and highlight every data entry for that Index.

    The logic to determine the xIndex - when user start panning, I know the location, and I will translate it into the closest xIndex; same as the ending point, so we know the start xIndex and end xIndex