Giter Site home page Giter Site logo

Comments (12)

PhilJay avatar PhilJay commented on May 5, 2024

So your problem is that you can set the scale minimum so that the user cannot fully zoom out the x-axis, but the starting position is not correct / cannot be changed?

from mpandroidchart.

Praveen2106 avatar Praveen2106 commented on May 5, 2024

Yes. Exactly. Since it is a timeline chart, I would like to start from last which will be latest entry.

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

Very well. Thankfully, that does not look like that a major issue to me.

I am going to look into that problem within the next hours and will hopefully be able to push a quick fix alongside with some other changes until tomorrow night (Europe), at the latest.

from mpandroidchart.

Praveen2106 avatar Praveen2106 commented on May 5, 2024

Thanks Phil.

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

I have now implemented this feature in my local commit. The only problem for me is that I don't think it's good enough yet :-)

I will try to change the implementation to a way that is satisfying for me within the next few hours to push on master or push the features current implementation to the experimental banch.

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

Allright, the implementation is now complete and pushed to master.
You can see an example in the ExampleProject inside the LineChartActivity.

The basic functionality is as follows.

The new method centerViewPort(int xIndex, float val) makes it possible to aim the center of the view to a specific position inside the chart, described by the index on the x-axis and the value on the y-axis. This also works very well in combination with the setScaleMinima(...) method.

Example:
A chart containing 50 entries ranging from 0-1000 with their values.

Chart.setData(...);

// restrain x-axis
Chart.setScaleMinima(3f, 1f);

// center view to index 50 and value 500
Chart.centerViewPort(50, 500f);
//.. now view is positioned on the right side of the chart on the x-axis and centered on the y-axis

from mpandroidchart.

Praveen2106 avatar Praveen2106 commented on May 5, 2024

Thanks Phil. I'm going to test it right away !!

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

Allright. Please let me know if it works and if you are having any problems.

from mpandroidchart.

Praveen2106 avatar Praveen2106 commented on May 5, 2024

Sorry. It took time to get back. centerViewPort works fine. But i have to click somewhere on the Chart to make it work. Tried invalidating the chart after calling centerViewPort. But still doesn't work.

    mChart.setData(data);
    mChart.invalidate();

    mChart.centerViewPort(11, 92);
    mChart.invalidate();

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

Thank you for your response.
Indeed, there still was a minor issue in the implementation of the centerViewPort(...) method that caused the problem you described.
I managed to track down the bug and fix it.

It should now work as expected.

Just for the record, this is the correct implementation (you can also find it in the example project):

// first, set data
mChart.setData(...);

// restrain the maximum zoomout level, e.g.
mChart.setScaleMinima(3f, 3f);

// center the "camera" to your desired position
mChart.centerViewPort(xIndex, value);

// there should be no further need for calling invalidate()

from mpandroidchart.

Praveen2106 avatar Praveen2106 commented on May 5, 2024

It works fine now !! Thanks.

from mpandroidchart.

wenli135 avatar wenli135 commented on May 5, 2024

Still met this problem with the latest release, the chart show correctly only after touch it

from mpandroidchart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.