I’m using ChartFactory.getTimeChartView method from the achartengine excellent library.
I show only the last week of records, allowing the user to pan to left for seeing previous records, using renderer.setXAxisMin(OneWeekBefore); property.
I have 2 questions :
a) How to allow X-axis zoom in TimeChart ?
I can not zoom on the X axis despite zoom is enabled on both X and Y axis. I might use the zoom and pan limits in an inappropriate way but can’t find what/why.
b) How to alter the zoom button behaviour ?
I would like to alter the behaviour of the zoom button 1:1. Pressing this, the whole graph is shown instead of only the last week.
Here is the piece of code for the zooming properties setup :
// ZOOM
double[] panlimits = new double[] { XfirstRecord , maxdate, 0.0, Ymax * 1.2 };
renderer.setZoomEnabled(enabledXzoom, YenabledYzoom);
renderer.setZoomButtonsVisible(showZoomButtons);
renderer.setZoomRate(ZoomRate);
renderer.setPanLimits(panlimits);
renderer.setZoomLimits(panlimits);
renderer.setXAxisMin(OneWeekBefore);
Working update after checking Dan’s answer is as below, it works for me :
// ZOOM
double[] panlimits = new double[] { XfirstRecord, now, 0.0, Ymax * 1.2 };
renderer.setZoomEnabled(XenabledZoom, YenabledZoom);
renderer.setZoomButtonsVisible(showZoomButtons);
renderer.setZoomRate(ZoomRate);
renderer.setPanLimits(panlimits);
renderer.setZoomLimits(panlimits);
// SHOW ONLY last WEEK even after Zoom reset
renderer.setXAxisMin(OneWeekBefore);
renderer.setInitialRange(new double[] {OneWeekBefore, now, 0.0, Ymax * 1.2});
For the first question, the pan and zoom limits should be something like:
Does pinch zoom work?
For the second question, use: