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 direc开发者_JAVA技巧tly at any desired zoom level. How is that possible?
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.
精彩评论