6

My program creates a time series chart using JFreeChart (via Swing ChartPanel) and allows the user to zoom into it (using the ChartPanel's standard zoom feature). The program has parameters (such as smoothing) that can be tweaked at runtime; if tweaked, the chart is replaced using the ChartPanel's "setChart()" method. The timeframe, however, invariably stays the same across all tweaks.

When "setChart()" is called, the zoom position is reset so that the entire chart is shown. What I now want is for the zoom position to be preserved after the call to "setChart()", so that the user can observe tweak effects directly at any desired zoom level. How is that possible?

Maximilian
  • 127
  • 7
  • @ Maximilian hello i would be very interested in how you managed to preserve the zoom as mine keeps reverting back to the original position or zooms into the center..would you be able to advise? – Ingram May 03 '16 at 18:38

1 Answers1

6

ChartPanel has methods getScaleX() and getScaleY() that could be used to cache the current zoom state for later restoration by one of the zoom methods. There's a related example here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045