Charts: How to sync the scrolling of 2 charts

Created on 1 Dec 2017  Â·  8Comments  Â·  Source: danielgindi/Charts

Hello,

I’m new to programming and decided to try to use this wonderful library.

My question has been asked several times (as well on the Java community) but I have never been able to find an answer/solution or better an example, at least one I understand.

The question is, _can 2 charts be synchronized so that "manual" scrolling/paning done on one chart is replicated on the second one?_
I thought the solution was to use ChartViewDelegate and to work with chartTranslated but the method is not even called in my sample.

I create a sample application https://github.com/Lavallette/ChartSample if you want to have a look with

  • 2 charts
  • scrolling
  • zooming
  • auto updating chart

I’m certainly missing something but would love to get some help and advices.

Thank you.

PS: this is an MacOS application with xCode 9 in Swift 4

Most helpful comment

@Lavallette

func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat) {
        print("chartTranslated")

        if  chartView == combinedChartView {
            let currentMatrix = chartView.viewPortHandler.touchMatrix
            lineChartView.viewPortHandler.refresh(newMatrix: currentMatrix, chart: lineChartView, invalidate: true)
        }else {
            let currentMatrix = chartView.viewPortHandler.touchMatrix
            combinedChartView.viewPortHandler.refresh(newMatrix: currentMatrix, chart: combinedChartView, invalidate: true)
        }
    }

it's work !

https://github.com/KevinZK/chart.git try it

All 8 comments

you can try refreshWithNewMatrix: chart: invalidate:

@KevinZK Thanks for helping with me trying to solve my problem.
Any chance for you to give me more information or pointing me toward more details.

@Lavallette change this function "func chartTranslated(chartView: ChartViewBase, dX: CGFloat, dY: CGFloat)" to "func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat)" ,add a " _ " symbol
image

"func chartTranslated(chartView: ChartViewBase, dX: CGFloat, dY: CGFloat)" to
"func chartTranslated(chartView: ChartViewBase, dX: CGFloat, dY: CGFloat)" ,add ""
what is change ???

@thierryH91200 I made a mistake :), have rewrited the reply

Thanks @KevinZK. I did the change but the function is never called when scrolling. Can it be that it is only called on iOS and not MacOS?

@Lavallette

func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat) {
        print("chartTranslated")

        if  chartView == combinedChartView {
            let currentMatrix = chartView.viewPortHandler.touchMatrix
            lineChartView.viewPortHandler.refresh(newMatrix: currentMatrix, chart: lineChartView, invalidate: true)
        }else {
            let currentMatrix = chartView.viewPortHandler.touchMatrix
            combinedChartView.viewPortHandler.refresh(newMatrix: currentMatrix, chart: combinedChartView, invalidate: true)
        }
    }

it's work !

https://github.com/KevinZK/chart.git try it

@KevinZK You are right of course. Not sure what I did the first time.

Thank you very very much for your help, you are brightening my day.
Thumbs up.

Was this page helpful?
0 / 5 - 0 ratings