Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moveViewToX problem #450

Closed
Begoodi opened this issue Oct 6, 2015 · 8 comments
Closed

moveViewToX problem #450

Begoodi opened this issue Oct 6, 2015 · 8 comments

Comments

@Begoodi
Copy link

Begoodi commented Oct 6, 2015

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 :)

@Begoodi
Copy link
Author

Begoodi commented Oct 9, 2015

Nobody has an idea ?
Perhaps my question is not clear, in fact I just want to display items 90 to 100 of my 100 items array...

@liuxuan30
Copy link
Member

Well you opened another on SO: http://stackoverflow.com/questions/33038795/display-last-items-of-a-bar-chart-on-ios-charts/33049374#33049374
To answer your question, I cannot give you the exact solutions, but I can offer some ways you can try it:

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

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:#226

EDIT:
Quote from Daniel,

Actually it should work, as it is deferred already to the rendering code. 
But you should call it only after data is calculated (notifyDataSetChanged)

@danielgindi
Copy link
Collaborator

Actually it should work, as it is deferred already to the rendering code.
But you should call it only after data is calculated (notifyDataSetChanged)

‏בתאריך יום שבת, 10 באוקטובר 2015, Xuan [email protected] כתב:

Well you opened another on SO:
http://stackoverflow.com/questions/33038795/display-last-items-of-a-bar-chart-on-ios-charts/33049374#33049374

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:

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

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:#226
#226


Reply to this email directly or view it on GitHub
#450 (comment)
.

@Begoodi
Copy link
Author

Begoodi commented Oct 12, 2015

Hi Daniel,
Sorry but I don't understand your solution.
The moveViewToX function works properly as I can use it to go to the end of my bargraph and see last values.
What I would like is to display directly the graph in this position, today I'm obliged to display first values (1 to 10) an then go to values 90-100, and it makes the graph blink.
Any advise to display values 90-100 in my example directly ?

@liuxuan30
Copy link
Member

@Begoodi what Daniel means is that call moveViewToX after you set your chart data.

What's your purpose? Directly show 90-100 when the chart pop up, or first show 1-10 and then 90-10?

For the former one, have you tried it, plus my suggestions?

For the latter one, there is a pending request #318 for animate moveViewToX.

@liuxuan30 liuxuan30 reopened this Oct 12, 2015
@Begoodi
Copy link
Author

Begoodi commented Oct 12, 2015

Hi Liuxuan30, thanks for your answer.

My purpose is to directly show 90-100 when the chart pop up.

Calling moveViewToX after setting the data does not work, it still shows 1-10, and if I have to touch the barograph to display 90-100 (why I don't know).

I tried to subclass and use it in drawRect(), but didn't succeed, had lots of different errors. It must be my fault, not newbie, bur nearly ;)

I found a workaround by putting "barChartView.hidden = true" after calculations in viewDidLoad(), then in viewDidAppear() I use the moveViewToX function and then put "barChartView.hidden = true".
In that case I don't have the blink problem, I directly see 90-100 values.

The drawback is that I can't use the animation functions, because animations are done on values 1-10, and I hided this part of the display...

@liuxuan30
Copy link
Member

I guess you may want to learn more about the code, it seems possible to manipulate it if you know how to play with the matrix, viewpor handler, etc.

@marshtupa
Copy link

How to set view of chart to the end

During the chart configuration just find the last entry in dataSet and call chart.centerViewTo()

    private func viewChartFromTheEnd(chart: BarChartView) {
        let lastIndex = chart.data!.dataSets.first!.entryCount - 1
        let lastEntry = chart.data?.dataSets.first?.entryForIndex(lastIndex)
        chart.centerViewTo(xValue: lastEntry!.x, yValue: lastEntry!.y, axis: .right)
    }

Screen Recording 2021-10-29 at 12 06 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants