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

how to set zoom level manually ? #1

Closed
mohsenk opened this issue Oct 16, 2014 · 1 comment
Closed

how to set zoom level manually ? #1

mohsenk opened this issue Oct 16, 2014 · 1 comment

Comments

@mohsenk
Copy link

mohsenk commented Oct 16, 2014

Hi
thanks for this perfect chart library.
i have a small problem , in first time render chart labels are very close.
how i can set zoom manually in startup ?
i found this method , but dose not work

chart.zoom(0,0, -20);

Image

@lecho
Copy link
Owner

lecho commented Oct 16, 2014

Hi,
you are right, there was a problem with Chart.zoom() method, it didn't work for values below 0 and above 1.

I rewrote that method into new one Chart.setZoomLevel() and it's now in master branch. Let me know if that helps.

   /**
     * Programatically zoom chart to given point(viewport point). Call this method after chart data had been set.
     * 
     * @param x
     *            x within chart maximum viewport
     * @param y
     *            y within chart maximum viewport
     * @param zoomLevel
     *            value from 1 to maxZoom(default 14). 1 means chart has no zoom, 14 means chart has maximum zoom.
     * @param isAnimated
     *            set true if zoom should be animated.
     */
    public void setZoomLevel(float x, float y, float zoomLevel, boolean isAnimated);

Now you can zoom like that:

//set chart data first
chart.setLineChartData(yourData);
//zoom, in this example without animation
chart.setZoomLevel(chart.getMaximumViewport.centerX, chart.getMaximumViewport.centerY, newZoomLevel,  false);

So zoom should now work but I'm still not sure if this will solve your problem. Long labels are hard and slow to handle.

If you want to separate labels for X axis use axis.setMaxLabelChars() method.

Btw. you cannot zoom out beyond max viewport with Chart.setZoomLevel() method but you can change max viewport with Chart.setMaximumViewport() method.

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

No branches or pull requests

2 participants