简体   繁体   中英

Display last items of a bar chart on iOS-charts

I have a bar chart with 100 items. I only display 10 at a time, and I enabled scrolling. Everything is fine, but I would like to display the end of my graph instead of the beginning (fresh datas). The only way to do it is to use the moveViewToX function in viewDidAppear.

The problem is that the graph is first displayed and animated at the beginning, then goes to the end, which is not very beautiful. How can I do to display directly the graph at the right position ?

(When I move the moveViewToX function elsewhere than in viewDidAppear it does not work).

Thanks :)

Solved same problem by delaying moveViewToX function call by 0.1 seconds

func viewDidLoad() {
    // ... 

    let when = DispatchTime.now() + 0.1
    DispatchQueue.main.asyncAfter(deadline: when) {
        chartView.moveViewToX(lastXAxisValue)
    }
}

I have seen your question on github, so please don't duplicate it.

I am guessing because you are putting moveViewToX in viewDidAppear , it is in async mode with the chart rendering, so you cannot control it.

To answer your question, I cannot give you the exact solutions, but I can offer some ways you can try it:

  1. subclass the chart view, call moveViewToX() somewhere in the chart view code, like the last line of drawRect() , to see if it works;

  2. If you are familiar with ChartTransformer, there is a method called refresh in ChartViewPortHandler , it should be able to navigate to anywhere as long as you know how to play with the matrix. Check out this post: https://github.com/danielgindi/ios-charts/issues/226

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM