Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFreeChart: Preserve zoom position when updating chart

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?

like image 541
Maximilian Avatar asked Sep 20 '11 08:09

Maximilian


1 Answers

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.

like image 157
trashgod Avatar answered Oct 23 '22 05:10

trashgod