Search code examples
androidachartengine

AChartEngine Android - reset zoom and pan of graph?


I am building an Android Application and I am using AChartEngine to display a graph and values I obtain.

I am able to graph the values I have properly. However, once the user zooms in and pans around my graph, it becomes difficult to view the data. One option I considered is to display a "redraw graph" button where once the user clicks it, the graph would redraw itself to the original state, zoom and pan would also reset.

Here's by code thus far:

public void redrawGraph(View view){
    chartView.repaint();
}

where redrawGraph is a the onClick function of my button and chartView is an object of type GraphicalView.

However, that does seem to do anything as it only repaints changes in my graph (if I added/removed series renderers, series, etc).

How can I reset the zoom and pan of graphs in AChartEngine?


Solution

  • My answer refers to XY/time charts. First you have to enable the external zoom feature in every renderer you use. The snippet below shows the code for accomplishing this:

    yourMultipleSeriesRenderer.setExternalZoomEnabled(true);
    

    In your method redrawGraph you then have to execute the command shown below:

    public void redrawGraph(View view) {
        chartView.zoomReset();
    }
    

    This works great for me. If you need any further information leave a comment.