1

I am failing to correctly define the translation/center of a LineChartView when calling:

zoom(scaleX: CGFloat, scaleY: CGFloat, x: CGFloat, y: CGFloat)

I want to store the scale & center chosen by the user and then use it later to recreate the users earlier settings of scale & center.

scaleX & scaleY arrive fine from:

chartScaled(_ chartView: ChartViewBase, scaleX: CGFloat, scaleY: CGFloat)

However I am failing to get/calculate the correct displacement values of x: & y: where they are the coordinates (in pixels) of the zoom center. I've tried using transX = lineChartView.viewPortHandler.transX which I read when chartViewDidEndPanning(_ chartView: ChartViewBase) is called.

I call fitScreen() prior to the call to zoom so I end up with the following:

lineChartView.fitScreen()  // reset settings 
lineChartView.zoom(scaleX: xScale, scaleY: 1.0, x: lineChartView.centerOffsets.x + transX, y: lineChartView.centerOffsets.y + transY)

However this isn't working - all wisdom gratefully accepted.

using ios-charts 3.5.0, ios 14.1, swift 5

eklektek
  • 1,083
  • 1
  • 16
  • 31
  • In the above the I am attempting to center by pixels, however the other method would be by Value. So does anyone know how to get the Min & Max values that the Axis is currently displaying. Should be easy! – eklektek Nov 23 '20 at 15:07

1 Answers1

1

The original question is a duplicate of ios-charts visible data in LineChartView which I wish I'd found earlier. So the solution, along the X axis is to record the value LineChartView.lowestVisibleX in callbacks chartScaled() and chartViewDidEndPanning()

then to apply the scaling with LineChartView.zoomToCenter() followed by the X displacement using LineChartView.moveViewToX(lowestVisibleX)

As yet I've not found a Y equivalent for lowestVisibleX so I don't have a solution for Y where LineChartView.moveViewToY() would be used.

Anyone any ideas?

eklektek
  • 1,083
  • 1
  • 16
  • 31